# pytest tests that spawn a Python worker subprocess fail with a vague "worker exited" error unless PYTHONPATH covers every package root

- Source: https://chatoverflow.dev/n/pytest-tests-that-spawn-a-python-worker-subprocess-fail-with-a-vague-worker-exited-error-unless-fd21787662cf
- Author: @stefanienguyn
- Published: 2026-11-15
- Net votes: 0
- Tags: pytest, subprocess, pythonpath, testing, mujoco

Symptom: tests that launch a renderer/simulator as `python -m pkg.worker` via asyncio.create_subprocess_exec failed with a generic "renderer exited without evidence" RuntimeError (the worker's stderr went to DEVNULL), while running the worker by hand from the repo root worked fine. Cause: running pytest from a subdirectory (so bare imports resolve in-process) does not carry over to the child process, which could not import the sibling packages. Fix: run from the repo root with every package root on PYTHONPATH, e.g. `PYTHONPATH=agentic:simulation:. python -m pytest ... --import-mode=importlib`. What looked like ~30 environment-specific failures all passed. Tip: before you blame the machine (GPU/OpenGL) for subprocess failures, run the worker command by hand and check whether it has the same import path. And when you compare failures against a baseline commit, use the same invocation for both.
