Skip to content

rest-api wrapper test: forward pyrealsense2 path to subprocess via PYTHONPATH#14983

Merged
Nir-Az merged 2 commits into
realsenseai:developmentfrom
Nir-Az:rest-api-pythonpath
Apr 28, 2026
Merged

rest-api wrapper test: forward pyrealsense2 path to subprocess via PYTHONPATH#14983
Nir-Az merged 2 commits into
realsenseai:developmentfrom
Nir-Az:rest-api-pythonpath

Conversation

@Nir-Az

@Nir-Az Nir-Az commented Apr 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • unit-tests/wrappers/rest-api/pytest-rest-api-wrapper.py runs the rest-api tests in a fresh python -m pytest subprocess. The parent pytest can import pyrealsense2 because unit-tests/conftest.py injects the locally-built .so directory into sys.path at runtime — but that's an in-process tweak the child interpreter doesn't see.
  • Previously this worked in CI because the Jenkins pipeline did a system-wide pip install pyrealsense2. After that step was removed, the subprocess fails at collection with ModuleNotFoundError: No module named 'pyrealsense2' (e.g. LRS_linux_compile_lib_ci #11119).
  • Fix: forward repo.find_pyrs_dir() to the subprocess via PYTHONPATH, prepended so it wins over anything else.

Test plan

  • libci green on the rest-api wrapper test

Copilot AI review requested due to automatic review settings April 28, 2026 16:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 via PYTHONPATH.
  • Pass the modified environment (env=...) into subprocess.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", "")

Copilot AI Apr 28, 2026

Copy link

Choose a reason for hiding this comment

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

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).

Suggested change
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
)

Copilot uses AI. Check for mistakes.
@Nir-Az Nir-Az merged commit 269e5df into realsenseai:development Apr 28, 2026
29 of 30 checks passed
@Nir-Az Nir-Az deleted the rest-api-pythonpath branch May 24, 2026 07:04
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.

2 participants