Skip to content

test: keep existing PYTHONPATH in test_noxfile_script_mode - #1190

Merged
henryiii merged 1 commit into
wntrblm:mainfrom
devtechedge:test/preserve-pythonpath-script-mode
Sep 29, 2026
Merged

henryiii merged 1 commit into
wntrblm:mainfrom
devtechedge:test/preserve-pythonpath-script-mode

Conversation

@devtechedge

Copy link
Copy Markdown
Contributor

test_noxfile_script_mode now prepends the fake nox-999 package to PYTHONPATH instead of replacing it.

Fixes #1189

When nox is importable only through PYTHONPATH, as in FreeBSD ports where the staged install is exposed that way during tests, the replaced value drops nox and the subprocess fails with No module named nox.

The failure only shows up when the whole file runs, because earlier in-process tests leave the working directory at a noxfile directory (via os.chdir in nox/tasks.py), so the source tree is no longer on sys.path either.

The fake nox-999 metadata stays first on the path, so the test still covers the #1157 behavior.

This is a test-only change and nox/_cli.py is untouched.

To reproduce the ports setup, I made a venv with only the runtime dependencies plus pytest and staged nox with uv pip install --no-deps --target /tmp/stage ..

Before this change:

$ PYTHONPATH=/tmp/stage python -m pytest tests/test_main.py -o addopts=
E       AssertionError: assert 1 == 0
...
/tmp/nox1189-venv/bin/python: No module named nox
FAILED tests/test_main.py::test_noxfile_script_mode - AssertionError: assert ...
1 failed, 130 passed, 2 skipped

After this change:

$ PYTHONPATH=/tmp/stage python -m pytest tests/test_main.py -o addopts=
131 passed, 2 skipped

The normal session still passes:

$ nox -s tests-3.12 -- tests/test_main.py -k script_mode
4 passed

nox -s lint is clean as well.

The test replaced PYTHONPATH with the directory holding the fake nox-999
metadata. When nox is only importable through PYTHONPATH, as in FreeBSD
ports, the subprocess then fails with "No module named nox". Prepend the
fake package instead so the existing path is kept.

Fixes #1189
devtechedge added a commit to devtechedge/oss-contributions that referenced this pull request Sep 28, 2026

@henryiii henryiii left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@henryiii
henryiii merged commit fd98dc7 into wntrblm:main Sep 29, 2026
22 checks passed
@devtechedge

Copy link
Copy Markdown
Contributor Author

I appreciate the fast review and merge, Henry.

You approved and merged it within a day, which meant a lot.

Reproducing the FreeBSD ports setup with a staged install on PYTHONPATH taught me how the os.chdir side effect hides this failure in a full-file run.

It was genuinely fun getting this one across the line!

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 test fails

2 participants