Skip to content

Wheel ships top-level tests/ package — collides with downstream test suites #63

Description

@Cadene

Hello there! Thanks for maintaining draccus :)

I wanted to raise an important issue that causes downstream projects relying on draccus to have issues with their tests:

draccus 0.10.0 installs 28 files under a top-level tests/ package into site-packages, including tests/__init__.py and tests/conftest.py.

$ grep "^tests/" .venv/lib/python3.12/site-packages/draccus-0.10.0.dist-info/RECORD | wc -l
28

This causes a namespace collision for any project whose own tests/ directory uses PEP 420 namespace packages (i.e. no __init__.py). Because draccus's tests/__init__.py makes it a regular package, Python's import machinery always resolves import tests to the draccus copy — regardless of sys.path ordering — since regular packages take precedence over namespace packages.

In practice this means downstream projects cannot remove their tests/__init__.py files without their from tests.xxx.conftest import … cross-imports breaking at runtime (they resolve to draccus's tests/conftest.py instead).

Suggested fix

Exclude tests from the wheel by adding an explicit exclude in pyproject.toml:

[tool.setuptools.packages.find]
exclude = ["tests", "tests.*"]

This is a well-documented anti-pattern — see [pypa/setuptools#3340](pypa/setuptools#3340) and the [Python Packaging User Guide](https://packaging.python.org/en/latest/guides/using-testpypi/).

Environment

  • draccus 0.10.0
  • Python 3.12
  • pip / setuptools

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions