astral-sh/ruff

INP001 false positive in tests folder

Open

#6,474 opened on Aug 10, 2023

View on GitHub
 (11 comments) (8 reactions) (0 assignees)Rust (2,088 forks)batch import
help wanted

Repository metrics

Stars
 (47,527 stars)
PR merge metrics
 (Avg merge 3d 8h) (573 merged PRs in 30d)

Description

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.

Contributor guide