Skip to content

DEP004 false positive for dev dependencies in test files #1533

@jamesbraza

Description

@jamesbraza

Describe the issue

To work around #302, I am un-excluding tests from the current DEFAULT_EXCLUDE like so:

[tool.deptry]
exclude = ["\\.direnv", "\\.git", "\\.venv", "setup\\.py", "venv"]

Secondly, to work around #1531, I have:

[tool.deptry]
optional_dependencies_dev_groups = ["dev"]

These two configurations expose a DEP004 false positive, where now testing dependencies in dev extra are marked like so:

  tests/test_a.py: DEP004 'pytest' imported but declared as a dev dependency

Minimal way to reproduce the issue

Play around with https://github.com/Future-House/ldp/blob/v0.45.1/packages/lmi/pyproject.toml#L40-L75

Expected behavior

Dev dependency imports in test files should not trigger DEP004, since tests are the expected place for dev dependencies to be used.

A possible solution would be to allow mapping directories to dependency groups, so deptry understands that imports in tests/ are expected to use dev dependencies.

Additional context

The workaround is to manually list every dev package in per_rule_ignores for DEP004, which is fragile and defeats the purpose of DEP004.

Environment

  • deptry version: 0.25.1
  • Python version: 3.13.5
  • Operating system (e.g. Ubuntu 22.04, Windows 11): Darwin 25.3.0 arm64

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions