Skip to content

Add repo root to pytest pythonpath so bare pytest works - #4

Closed
ARC345 wants to merge 1 commit into
libingzheren:mainfrom
ARC345:fix/pytest-pythonpath
Closed

ARC345 wants to merge 1 commit into
libingzheren:mainfrom
ARC345:fix/pytest-pythonpath

Conversation

@ARC345

@ARC345 ARC345 commented Oct 4, 2026

Copy link
Copy Markdown

Problem

Running the test suite with plain pytest (rather than python -m pytest) fails during collection:

ERROR collecting tests/test_public_release.py
ModuleNotFoundError: No module named 'scripts'

python -m pytest puts the current directory on sys.path; the pytest entry point does not, so from scripts.check_public_release import ... can't be resolved.

Change

Add pythonpath = . to pytest.ini so both invocations behave the same. The option is available since pytest 7.0, which matches the existing pytest>=7,<10 pin in requirements-dev.txt. No code or dependency changes.

Verification

On Python 3.11 with requirements-dev.txt installed:

  • Before: pytest -q tests/test_public_release.py → collection error above.
  • After: pytest -q → 217 passed, 2 skipped.
  • After: python -m pytest -q → 217 passed, 2 skipped (unchanged).
  • python scripts/check_public_release.py passes.

No changelog entry since this only affects running the tests locally.

Running bare `pytest` failed to collect tests/test_public_release.py with
"No module named 'scripts'", because unlike `python -m pytest` it does not
put the working directory on sys.path. Setting pythonpath = . makes both
invocations behave the same.
@FredJiang0324

Copy link
Copy Markdown
Collaborator

Thanks for the contribution. Closing this PR as we don’t plan to make this change.

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.

2 participants