Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytest issues spurious warnings about classes with __init__ methods #924

Closed
pont-us opened this issue Jan 30, 2024 · 0 comments · Fixed by #925
Closed

pytest issues spurious warnings about classes with __init__ methods #924

pont-us opened this issue Jan 30, 2024 · 0 comments · Fixed by #925

Comments

@pont-us
Copy link
Member

pont-us commented Jan 30, 2024

Describe the bug
Running the test suite produces the following warnings:

test/util/test_progress.py:15
  /home/appveyor/projects/xcube/test/util/test_progress.py:15: PytestCollectionWarning: cannot collect test class 'TestProgressObserver' because it has a __init__ constructor (from: test/core/gen2/remote/test_generator.py)
    class TestProgressObserver(ProgressObserver):

test/core/gridmapping/test_base.py:19
  /home/appveyor/projects/xcube/test/core/gridmapping/test_base.py:19: PytestCollectionWarning: cannot collect test class 'TestGridMapping' because it has a __init__ constructor (from: test/core/gridmapping/test_base.py)
    class TestGridMapping(GridMapping):

test/util/test_extension.py:132
  /home/appveyor/projects/xcube/test/util/test_extension.py:132: PytestCollectionWarning: cannot collect test class 'TestComponent' because it has a __init__ constructor (from: test/util/test_extension.py)

This is misleading: the classes in question are helper classes for testing, not containers for actual tests, so there is nothing for pytest to collect and the __init__ methods are fine. However, pytest has no way of knowing this.

To Reproduce
Steps to reproduce the behavior:

  1. Run test suite (commit 98f6a37).
  2. Observe warnings.

Expected behavior
The warnings described above should not appear.

Suggested solution
If the class names did not start with Test, pytest would not attempt to scan them for tests. Prefixing the class names with an underscore would suffice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant