Skip to content

Defer hub creation so discovery prints are visible in pytest#14919

Merged
Nir-Az merged 4 commits into
realsenseai:developmentfrom
Nir-Az:hub-prints
Apr 14, 2026
Merged

Defer hub creation so discovery prints are visible in pytest#14919
Nir-Az merged 4 commits into
realsenseai:developmentfrom
Nir-Az:hub-prints

Conversation

@Nir-Az

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

Copy link
Copy Markdown
Collaborator

Summary

  • Hub discovery (device_hub.create()) was running at devices.py import time, before pytest's logging was configured — so the debug prints (Acroname, YKUSH, UniFi discovery, CombinedHub port mapping) were swallowed by pytest's stdout capture
  • Moved hub creation into an explicit init_hub() function called after logging is ready
  • Both pytest (conftest.py) and the legacy runner (run-unit-tests.py) now call devices.init_hub() before using the hub

Motvation 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 visible
  • python run-unit-tests.py --help — loads without errors
  • Jenkins CI build to verify full output on a machine with actual hubs

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 12, 2026 11:51

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 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.py import-time code into a new devices.init_hub() function.
  • Call devices.init_hub() from pytest startup (conftest.py) and the legacy runner (run-unit-tests.py).
  • Ensure the devices.py CLI 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.

Comment thread unit-tests/py/rspy/devices.py Outdated
Comment on lines +54 to +59

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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed — added _hub_attempted flag so discovery runs at most once.

global hub
if hub is None:
hub = device_hub.create()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed — added init_hub() call at the top of query() as a safety net.

Comment on lines +816 to 819
init_hub()
if hub:
if not hub.is_connected():
hub.connect()

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed — guarded with if hub: in the finally block.

Comment thread unit-tests/py/rspy/devices.py Outdated
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

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Pre-existing bug — fixed by replacing sys.path[:-1] with sys.path.remove(pyrs_dir).

@Nir-Az Nir-Az requested a review from remibettan April 14, 2026 10:20
@Nir-Az Nir-Az merged commit a5fa183 into realsenseai:development Apr 14, 2026
29 of 30 checks passed
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.

3 participants