fix(testing): prevent host Python env from leaking into Flutter tests - #6747
Merged
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 |
FeodorFitsner
approved these changes
Aug 14, 2026
13 tasks
FeodorFitsner
added a commit
that referenced
this pull request
Aug 15, 2026
) * fix(testing): harden Flutter test env against host-Python leakage Follow-up to #6747, which stripped PYTHONPATH/PYTHONHOME from the `flutter test` subprocess so an IDE-injected debugger/sitecustomize path could not reach the interpreter embedded in the app under test. Two more host-Python knobs reach that interpreter the same way: * PYTHONEXECUTABLE - macOS framework builds use it to seed sys.executable, and a host value points at the IDE's interpreter, not the packaged app's. * PYTHONNOUSERSITE - user site-packages is opt-out, so leaving it unset lets a host ~/.local/lib/pythonX.Y/site-packages whose version matches the embedded interpreter leak in. It is now set rather than removed. The environment is built in a `_flutter_subprocess_env()` helper instead of inline at the call site, which gives the rationale one home and makes the part that is actually testable - which variables are dropped and which survive - unit-testable without launching Flutter. Adds the changelog entry #6747 shipped without. * fix(testing): keep the env helper out of the numpy-importing module The unit suite runs as `uv run --no-dev --group test`, whose environment has only pytest and pytest-asyncio - numpy, pillow and scikit-image live in the `dev` group. Importing `flet.testing.flet_test_app` therefore fails at collection in CI with `ModuleNotFoundError: No module named 'numpy'`, which is why no unit test imported that subtree before. Move the helper to `flet.utils.environment.without_host_python_config()`, a module with no dependencies beyond the stdlib, and have `flet_test_app` call it. The function never needed anything from `FletTestApp` - it is a pure transform over an environment mapping - and it now takes the mapping as an optional argument, so the tests exercise it without touching `os.environ`. Verified by importing the module with numpy/PIL/skimage blocked on the meta path, reproducing the CI environment.
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: