fix(testing): prevent host Python env from leaking into Flutter tests - #6747
fix(testing): prevent host Python env from leaking into Flutter tests#6747PythBuster 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.
|
|
|
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 |
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: