Defer hub creation so discovery prints are visible in pytest#14919
Conversation
There was a problem hiding this comment.
Pull request overview
This PR defers device_hub.create() so hub discovery output isn’t swallowed by pytest’s stdout/logging capture during import-time initialization.
Changes:
- Move hub creation out of
rspy/devices.pyimport-time code into a newdevices.init_hub()function. - Call
devices.init_hub()from pytest startup (conftest.py) and the legacy runner (run-unit-tests.py). - Ensure the
devices.pyCLI path initializes the hub before attempting hub operations.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| unit-tests/py/rspy/devices.py | Adds init_hub() and updates CLI flow to create the hub after logging is configured. |
| unit-tests/conftest.py | Initializes the hub during pytest_configure before device querying/parametrization. |
| unit-tests/run-unit-tests.py | Initializes the hub in the legacy test runner before device discovery/query. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| def init_hub(): | ||
| """Create the hub instance. Call after logging is configured so discovery prints are visible.""" | ||
| global hub | ||
| if hub is None: | ||
| hub = device_hub.create() |
There was a problem hiding this comment.
Fixed — added _hub_attempted flag so discovery runs at most once.
| global hub | ||
| if hub is None: | ||
| hub = device_hub.create() | ||
|
|
There was a problem hiding this comment.
Fixed — added init_hub() call at the top of query() as a safety net.
| init_hub() | ||
| if hub: | ||
| if not hub.is_connected(): | ||
| hub.connect() |
There was a problem hiding this comment.
Fixed — guarded with if hub: in the finally block.
| import pyrealsense2 as rs | ||
| log.d( rs ) | ||
| hub = device_hub.create() # if there's no hub, this will hold None | ||
| sys.path = sys.path[:-1] # remove what we added |
There was a problem hiding this comment.
Pre-existing bug — fixed by replacing sys.path[:-1] with sys.path.remove(pyrs_dir).
Summary
device_hub.create()) was running atdevices.pyimport time, before pytest's logging was configured — so the debug prints (Acroname, YKUSH, UniFi discovery, CombinedHub port mapping) were swallowed by pytest's stdout captureinit_hub()function called after logging is readyconftest.py) and the legacy runner (run-unit-tests.py) now calldevices.init_hub()before using the hubMotvation was to see the hub prints at the start of pytest like we see it for run-unit-tests.py
Test plan
python -m pytest --debug --collect-only— hub discovery prints now visiblepython run-unit-tests.py --help— loads without errors🤖 Generated with Claude Code