astral-sh/ruff

INP001 false positive in tests folder

Open

#6474 aperta il 10 ago 2023

Vedi su GitHub
 (11 commenti) (8 reazioni) (0 assegnatari)Rust (2088 fork)batch import
help wanted

Metriche repository

Star
 (47.527 star)
Metriche merge PR
 (Merge medio 3g 8h) (573 PR mergiate in 30 g)

Descrizione

The recommended Python + Pytest layout is

  • src/
    • mypkg/
      • __init__.py
      • subpkg/
        • __init__.py
  • tests/
    • test_thing.py
    • test_more/
      • test_other_thing.py

Notably, tests and all files under it aren’t packages. The recommended import mode enforces that you can’t import from them.

Therefore INP001 shouldn’t trigger when tests is on top level of the project.

In fact, it would be great to have both a rule that enforces the opposite and to ensure that tests/**/test_*.py files don’t import things from each other.

Guida contributor