rest-api wrapper test: forward pyrealsense2 path to subprocess via PYTHONPATH#14983
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes rest-api wrapper subprocess test collection failures by ensuring the child python -m pytest process can import the locally-built pyrealsense2 (which is normally added to sys.path only in the parent pytest process via unit-tests/conftest.py).
Changes:
- Compute
pyrs_dir = repo.find_pyrs_dir()in the wrapper test and forward it to the subprocess viaPYTHONPATH. - Pass the modified environment (
env=...) intosubprocess.run(...)so the child interpreter sees the path.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| env = os.environ.copy() | ||
| pyrs_dir = repo.find_pyrs_dir() | ||
| if pyrs_dir: | ||
| env["PYTHONPATH"] = pyrs_dir + os.pathsep + env.get("PYTHONPATH", "") |
There was a problem hiding this comment.
When PYTHONPATH is unset or empty, pyrs_dir + os.pathsep + "" leaves a trailing path separator, which introduces an empty entry in PYTHONPATH (interpreted as the current working directory on sys.path). This can change import precedence and reduce test isolation. Build PYTHONPATH so you only add os.pathsep + existing when an existing value is non-empty (otherwise set it to pyrs_dir alone).
| env["PYTHONPATH"] = pyrs_dir + os.pathsep + env.get("PYTHONPATH", "") | |
| existing_pythonpath = env.get("PYTHONPATH", "") | |
| env["PYTHONPATH"] = ( | |
| pyrs_dir + os.pathsep + existing_pythonpath | |
| if existing_pythonpath | |
| else pyrs_dir | |
| ) |
Summary
unit-tests/wrappers/rest-api/pytest-rest-api-wrapper.pyruns the rest-api tests in a freshpython -m pytestsubprocess. The parent pytest canimport pyrealsense2becauseunit-tests/conftest.pyinjects the locally-built.sodirectory intosys.pathat runtime — but that's an in-process tweak the child interpreter doesn't see.pip install pyrealsense2. After that step was removed, the subprocess fails at collection withModuleNotFoundError: No module named 'pyrealsense2'(e.g. LRS_linux_compile_lib_ci #11119).repo.find_pyrs_dir()to the subprocess viaPYTHONPATH, prepended so it wins over anything else.Test plan