Warn about `__init__.py` in tests
See original GitHub issueRule request
Description
It is the best practice to remove __init__.py
from tests folder.
https://docs.pytest.org/en/latest/goodpractices.html#tests-outside-application-code
Rationale
So, this linter should warn users about incorrect setup. It is probably a good idea to make this configurable:
- tests path
- style: with
__init__.py
or without
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Pytest collection warning due to __init__ constructor
When I run the test, I get a collection warning: PytestCollectionWarning: cannot collect test class 'TestCase_AddStar' because it has a init ...
Read more >Warn about missing __init__.py · Issue #2773 · python/mypy
If mypy can't find a package, it could see if the directory exists somewhere in the module search path without an __init__.py ,...
Read more >How to capture warnings — pytest documentation
Similar to Python's warning filter and -W option flag, pytest provides its own -W flag to control which warnings are ignored, displayed, or...
Read more >How to Fix a PytestCollectionWarning about WebTest's ...
This happens because pytest tries to collect the TestApp class as a test class, but it finds it is incompatible. pytest supports tests...
Read more >Python developer reference for Azure Functions
Based on this definition, the __init__.py file that contains the ... by the static type checker and not supported by Python test frameworks:....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Having this configurable is a good idea. While pytest emulates the presence of
__init__.py
, there are cases when this may break (especially when you also have to support Python 2).I personally like not having
__init__.py
, but FTR here’s some corner cases that I met:It’s probably worth mentioning the presence of the exceptional cases in the doc for the rule, once implemented.