question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Warn about `__init__.py` in tests

See original GitHub issue

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:

  1. tests path
  2. style: with __init__.py or without

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
sobolevncommented, Apr 22, 2020
  1. When you have duplicate test names
0reactions
webknjazcommented, Apr 22, 2020

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:

  1. various tooling does not support/understand implicit namespaces or such support is implemented poorly
  2. 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found