Repository navigation
test(cli): set the fixture's env vars through monkeypatch so they cannot leak - #741
Merged
Merged
Conversation
…not leak tests/cli/conftest.py::test_environment wrote FLUID_ENV and FLUID_LOG_LEVEL straight into os.environ and restored a snapshot at teardown. Autouse fixtures in the root conftest and in tests/cli's own create monkeypatch first, so monkeypatch's undo ran after that restore. A test that called monkeypatch.delenv or monkeypatch.setenv on either variable recorded the fixture's value as the original, and the undo put it back for the rest of the session. test_cli_output_keeps_brackets.py's _clean_env delenvs every FLUID_* key; test_cli_smoke.py and test_binding_path_anchoring.py leaked the same way. Every later subprocess test inherited FLUID_LOG_LEVEL=DEBUG, and tests/test_overlay_keyed_merge.py::TestValidateStrict saw the loader log its warning a second time: 3 failures whenever it ran after the brackets file in one worker. Both variables now go through monkeypatch, which records the true original. The snapshot restore stays for anything a test changes in os.environ directly. tests/cli/test_conftest_env_isolation.py checks, at module teardown, that neither variable outlives the module; it fails on the old fixture and on a revert of either variable alone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The 3
tests/test_overlay_keyed_merge.py::TestValidateStrictfailures onmainare notrandom. They are a test-isolation leak, and they appear whenever that file runs after
tests/cli/test_cli_output_keeps_brackets.pyin the same worker.How the leak worked:
tests/cli/conftest.py::test_environmentwroteFLUID_ENVandFLUID_LOG_LEVELstraight into
os.environand restored a snapshot at teardown._disable_copilot_self_eval) and intests/cli/conftest.py(_reset_cli_process_state) createmonkeypatchfirst. Somonkeypatch.undo()ran after that restore.monkeypatch.delenvormonkeypatch.setenvon either variablerecorded the fixture's value as the original. The undo then put it back for the rest
of the session.
test_cli_output_keeps_brackets.py's_clean_envdelenvs everyFLUID_*key.test_cli_smoke.pyandtest_binding_path_anchoring.pyleaked the same way.FLUID_LOG_LEVEL=DEBUG.TestValidateStrictthen saw the loader's
overlay_patch_retargetedwarning on stderr a second time(
assert 2 == 1).The DuckDB 2.0 port PR builds a clean subprocess env inside
TestValidateStrict, whichfixes the symptom. This PR removes the cause: both variables now go through
monkeypatch.setenv, which records the true original. The snapshot restore stays, foranything a test changes in
os.environdirectly. The comment on #740's_cli_env()nolonger blames xdist workers; the helper stays, since it also keeps out a debug switch a
developer exported.
Type of Change
Documentation
Checklist
pytest)ruff checkandblackwith no errorspython scripts/add_license_headers.py;examples/**exempt)Testing
tests/cli/test_conftest_env_isolation.py. At module teardown it asserts thatneither variable outlived the module. It fails on the old fixture
(
{'FLUID_ENV': 'test', 'FLUID_LOG_LEVEL': 'DEBUG'} outlived this module's tests),and it also fails when only one of the two variables is reverted. It passes here.
pytest tests/cli/test_cli_output_keeps_brackets.py tests/test_overlay_keyed_merge.py::TestValidateStrict -p no:randomly:3 failed on
main, 20 passed here.tests/cli: 2685 passed. The remaining failures happen the same way onmain: sqlglot version skew in the local venv, plus subprocess and MCP-live timeoutsunder machine load.
--setup-show. Itfound no new leak, either from keeping the snapshot restore beside monkeypatch or
under xdist or random order. It asked for the second variable to be pinned too,
which is done.