Skip to content

fix: __init__.py (root) cannot be imported, breaks the entire test suite on pytest v.8.0.0+ - #91

Open
leopozh wants to merge 1 commit into
Roblox:mainfrom
leopozh:fix/init-breaking-pytest
Open

fix: __init__.py (root) cannot be imported, breaks the entire test suite on pytest v.8.0.0+#91
leopozh wants to merge 1 commit into
Roblox:mainfrom
leopozh:fix/init-breaking-pytest

Conversation

@leopozh

@leopozh leopozh commented Jul 31, 2026

Copy link
Copy Markdown

Anything pytest version 8.0.0 and later is erroring, when I first cloned into this repo the dev spec of pytest>=7.0.0 automatically set me at pytest 9.1.1

The __init__.py in root cannot get imported and the pytest tries to before going through every single test. The entire test suite errors when the repo is cloned by someone new.

Issue was here, this is a relative import

from .core.config import ExperimentConfig, ModelConfig, DataConfig, TrainingConfig, WandbConfig
$ python -c "import __init__"
ImportError: attempted relative import with no known parent package

When the __init__.py is present at the rootdir, pytest treats the root of the repo as a package and collects it as a Package node, and then Package.setup() imports the __init__.py once per test item.

This causes every single test to error during the setup, removing this leads to all of them passing because there's nothing wrong with them.

This issue is NOT visible in pytest 7, but this change doesn't break that behavior. Tested it on pytest version 7.4.4 has 28 passed with and without the __init__.py file (this is due to the test modules inserting the repo root onto sys.path, so the reliance on rootdir isn't present).

Nothing in the repo imports it. The only relative imports at the root level are itself (lines 9-10).

The sub-package init files under core/ utils/ and evaluations/eval_datasets/ sit inside different packages, so their relative imports arent affected.

Before 

28 errors in 4.45s

After 

28 passed in 7.68s

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant