flake8-pytest-style
flake8-pytest-style copied to clipboard
Warn about `__init__.py` in tests
Rule 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
Hi @sobolevn,
I'm not sure I agree that this rule should be enforced. Per the pytest docs, layout without __init__.py
files is only one of supported layouts, and an alternative layout with multiple packages and __init__.py
files is also supported. I've seen both in my experience, both have pros and cons, and I don't really feel that either of them should be enforced for all projects.
That's why I have added a note about a configuration:
It is probably a good idea to make this configurable:
tests path
style: with __init__.py or without
My bad, must've missed it :( I'll keep this in mind, thanks
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:
- various tooling does not support/understand implicit namespaces or such support is implemented poorly
- when the custom import machinery is implemented, it may conflict with what pytest does and it has to be disabled (this is the case I saw in Ansible, in particular)
It's probably worth mentioning the presence of the exceptional cases in the doc for the rule, once implemented.
- When you have duplicate test names
unless importlib mode is used, its wrong to drop them