test: Stabilize CLI runner subprocess path#6560
Conversation
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 79d89d66e5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| parent_paths = [path for path in sys.path if path] | ||
| existing_pythonpath = env.get("PYTHONPATH") | ||
| if existing_pythonpath: | ||
| parent_paths.append(existing_pythonpath) |
There was a problem hiding this comment.
Preserve child PYTHONPATH precedence
In workflows where PYTHONPATH intentionally contains an empty/current-directory entry for the CLI cwd (for example, .github/workflows/unit_tests.yml exports sdk/python:${PYTHONPATH}:$SITE_PACKAGES), appending the raw existing value after the parent sys.path moves parent site-packages and repo-root paths ahead of the temporary feature repo. Since cli_check_repo() only appends the feature repo path later, imports for repo-local providers or feature definition modules can resolve to an installed/root module with the same name, so CliRunner no longer exercises the isolated repo. Keep the original PYTHONPATH entries first, or add only parent-only paths after the child cwd entry.
Useful? React with 👍 / 👎.
What changed
CliRunnersubprocesses in unit tests.sys.pathentries toPYTHONPATHbefore invokingfeast.cli.cliin a child Python process.subprocess.run(...)andsubprocess.Popen(...)helper paths.Why
The unit-test workflow flaked on
unit-test-python (3.12, ubuntu-latest)while setting uptest_push_source_does_not_exist. The parent pytest process had imported Feast successfully, but the childfeast applysubprocess failed before the test body with:That points at the subprocess import environment rather than the test assertion. Passing through the parent process import path makes the CLI subprocess use the same repo/site-packages view as pytest.
Validation
uv run ruff check sdk/python/tests/utils/cli_repo_creator.pyuv run python -m pytest sdk/python/tests/unit/test_feature_server.py::test_push_source_does_not_exist -qfrom google.protobuf.timestamp_pb2 import TimestampusingCliRunner._subprocess_env()Note: local setup required
make install-python-dependencies-ci PYTHON_VERSION=3.12because this machine does not have apythonshim for the Makefile's default version detection.