Skip to content

🧪 test: restore inherited PYTHONPATH in native env-files test - #365

Open
sandrotosi wants to merge 3 commits into
pytest-dev:mainfrom
sandrotosi:test/keep-pythonpath-native-env-files
Open

sandrotosi wants to merge 3 commits into
pytest-dev:mainfrom
sandrotosi:test/keep-pythonpath-native-env-files

Conversation

@sandrotosi

@sandrotosi sandrotosi commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

#290 made test_native_env_files_override_ini forward the caller's PYTHONPATH to its pytest subprocess, so packagers who reach pytest-env only through PYTHONPATH can run it. The parametrization rewrite in #308 (640b2b9) dropped that again: the test clears the environment and passes only the scenario's own PYTHONPATH, so the subprocess can't import pytest_env.plugin and all 24 cases fail:

ModuleNotFoundError: No module named 'pytest_env'. Did you mean: 'test_env'?
...
ValueError: Pytest terminal summary report not found

We hit it packaging 1.8.8 for Debian, where pybuild runs the suite against the built wheel through PYTHONPATH.

The test now prepends the caller's PYTHONPATH, if set, to the scenario's value. When PYTHONPATH is unset, as under tox, the value is an empty string, which pytester drops when it builds the subprocess's PYTHONPATH (filter(None, ...) in Pytester.popen), so the subprocess environment is unchanged; the unset scenarios still see no pythonpath_marker and the set ones still see it.

This changes only a test, so there's no new test. I added a packaging news fragment because I can't apply the skip news label; feel free to drop it and use the label instead, as in #290.

Checked on Debian sid (Python 3.14.10, pytest 9.1.1, python-dotenv 1.2.1, pytest-mock 3.15.1), full suite:

plugin reachable through main this branch
PYTHONPATH only (built wheel unpacked) 24 failed, 171 passed 195 passed
installed, PYTHONPATH unset not run 195 passed

The 24 failures on main are all test_native_env_files_override_ini. The same change, carried as a Debian patch on 1.8.8, also passes the Debian build on Python 3.14 and 3.15. ruff 0.17.5 (format and check) and simplint 0.14.2, the versions pinned in .pre-commit-config.yaml, pass; I haven't run the other prek hooks.

🤖 Generated with Claude Code

pytest-dev#290 made test_native_env_files_override_ini forward the caller's
PYTHONPATH to its pytest subprocess; the rewrite in pytest-dev#308 dropped it again,
so the subprocess can't import pytest_env.plugin when the plugin is only
reachable through PYTHONPATH, and all 24 cases fail. Prepend the caller's
PYTHONPATH to the scenario's value; with PYTHONPATH unset the subprocess
environment is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sandrotosi and others added 2 commits November 26, 2026 02:03
simplint's conditional-in-test rule rejects the conditional dict
unpacking. Always set PYTHONPATH to the joined value instead: pytester's
popen rebuilds PYTHONPATH with filter(None, ...), which drops an empty
value, so the case without an inherited PYTHONPATH is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The news check needs a fragment or the skip news label, which only
maintainers can apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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