Skip to content

fix: explicit PYTHONPATH for isolated test subprocesses (#593)#594

Open
planetf1 wants to merge 1 commit intogenerative-computing:mainfrom
planetf1:fix/subprocess-pythonpath
Open

fix: explicit PYTHONPATH for isolated test subprocesses (#593)#594
planetf1 wants to merge 1 commit intogenerative-computing:mainfrom
planetf1:fix/subprocess-pythonpath

Conversation

@planetf1
Copy link
Contributor

@planetf1 planetf1 commented Mar 6, 2026

Explicit PYTHONPATH for isolated test subprocesses

Type of PR

  • Bug Fix
  • New Feature
  • Documentation
  • Other

Description

Fixes #593

Fixes an issue where tests spawned in isolated subprocess environments (such as via uv run pytest) fail with ModuleNotFoundError. The parent pytest process dynamically injects the package path into sys.path, but this memory state is not naturally inherited by child subprocess.Popen calls. This change explicitly resolves the repository root and injects it into the PYTHONPATH environment variable for both the heavy GPU test runner and the examples runner.

Verified locally, and confirmed working for both HuggingFace and vLLM test suites on LSF HPC nodes.

Testing

  • Tests added to the respective file if code was changed
  • New code has 100% coverage if code as added
  • Ensure existing tests and github automation passes (a maintainer will kick off the github automation when the rest of the PR is populated)

@github-actions
Copy link
Contributor

github-actions bot commented Mar 6, 2026

The PR description has been updated. Please fill out the template for your PR to be reviewed.

@mergify
Copy link

mergify bot commented Mar 6, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert|release)(?:\(.+\))?:

@planetf1 planetf1 changed the title fix: explicit PYTHONPATH for isolated test subprocesses (#592) fix: explicit PYTHONPATH for isolated test subprocesses (#593) Mar 6, 2026
@planetf1 planetf1 force-pushed the fix/subprocess-pythonpath branch from e71015c to 7fadb7d Compare March 6, 2026 09:21
@planetf1 planetf1 marked this pull request as ready for review March 6, 2026 09:21
@planetf1 planetf1 requested a review from a team as a code owner March 6, 2026 09:21

repo_root = str(pathlib.Path(__file__).parent.parent.parent.resolve())
env = os.environ.copy()
env["PYTHONPATH"] = f"{repo_root}{os.pathsep}{env.get('PYTHONPATH', '')}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One concern: Will this cause issues if someone has a PYTHONPATH already set? I'm guessing it would only cause issues if someone has some weird setup. To hedge against that, should we set the variable with PYTHONPATH=env.get('PYTHONPATH', "")<; or :>{repo_root}{os.pathsep}.

At the very least, I don't think it makes sense adding PYTHONPATH to the repo root if already exists. I think that will jumble the path.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can set it to have multiple paths (that's what I was trying to do with my quick example); you set it to the existing path if it exists and then add a link to the base repo as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subprocess-based tests (e.g. Examples) fail depending on environment tool due to missing PYTHONPATH

2 participants