fix(testing): prevent host Python env from leaking into Flutter tests - #6747
Open
PythBuster wants to merge 1 commit into
Open
fix(testing): prevent host Python env from leaking into Flutter tests#6747PythBuster wants to merge 1 commit into
PythBuster wants to merge 1 commit into
Conversation
FletTestApp started the Flutter integration-test process with the complete environment inherited from the host Python process. IDEs such as PyCharm add debugger and sitecustomize directories to PYTHONPATH. That value was inherited by `flutter test` and subsequently passed to the embedded Serious Python runtime. As a result, the packaged test app could exit before connecting to RemoteTester. Flutter then reported exit code 79 with "No tests were found", while the flet_app fixture failed during setup. Create an explicit environment for the Flutter subprocess and remove PYTHONPATH and PYTHONHOME before launching it. All Flet, Flutter and SERIOUS_PYTHON_* variables remain unchanged. This keeps host-only Python configuration out of the packaged runtime while preserving the environment required to build and execute integration tests. Verified with the PyCharm TeamCity pytest plugin and PyCharm helper paths present in the host PYTHONPATH.
Contributor
|
Optional follow-up, same rationale as this fix - not blocking.
Both are pre-existing hazards rather than anything this PR introduces, so they're fine as a separate change. If they do get added, it might be worth flipping the shape from a denylist of pops to a small helper that builds the env - something like: def _flutter_subprocess_env() -> dict[str, str]:
"""
Environment for the `flutter test` child. Host-Python configuration must
not reach the app's embedded interpreter: IDEs (PyCharm) inject debugger
and sitecustomize paths via PYTHONPATH, which the packaged app imports at
startup and dies on - surfacing as Flutter exit code 79, "No tests were
found", before RemoteTester ever connects. All FLET_*, FLUTTER_* and
SERIOUS_PYTHON_* variables are preserved.
"""
env = os.environ.copy()
for key in ("PYTHONPATH", "PYTHONHOME", "PYTHONEXECUTABLE"):
env.pop(key, None)
env["PYTHONNOUSERSITE"] = "1"
return envThat also makes the one testable part of this - which keys are dropped, which survive - unit-testable without launching Flutter, and it parallels |
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
FletTestApp started the Flutter integration-test process with the complete environment inherited from the host Python process.
IDEs such as PyCharm add debugger and sitecustomize directories to PYTHONPATH. That value was inherited by
flutter testand subsequently passed to the embedded Serious Python runtime.As a result, the packaged test app could exit before connecting to RemoteTester. Flutter then reported exit code 79 with "No tests were found", while the flet_app fixture failed during setup.
Create an explicit environment for the Flutter subprocess and remove PYTHONPATH and PYTHONHOME before launching it. All Flet, Flutter and SERIOUS_PYTHON_* variables remain unchanged.
This keeps host-only Python configuration out of the packaged runtime while preserving the environment required to build and execute integration tests.
Verified with the PyCharm TeamCity pytest plugin and PyCharm helper paths present in the host PYTHONPATH.
Test code
# Minimal test/reproduction code for reviewers, if applicable.Type of change
Checklist
website/sidebars.ymlfor breaking changes, removals, and deprecations, if applicable.Screenshots
Additional details
Summary by Sourcery
Bug Fixes: