Skip to content

Migrate live/options tests to pytest - #14987

Merged
Nir-Az merged 11 commits into
realsenseai:developmentfrom
OhadMeir:unit-tests
May 3, 2026
Merged

Nir-Az merged 11 commits into
realsenseai:developmentfrom
OhadMeir:unit-tests

Conversation

@OhadMeir

Copy link
Copy Markdown
Contributor

Tracked on [RSDSO-21353]

Summary

  • Migrates all 9 test files under unit-tests/live/options/ from the legacy rspy.test framework to pytest (pytest-*.py)
  • Adds pytest-dependency plugin to handle on_fail=test.ABORT semantics: prerequisite tests are marked with @pytest.mark.dependency(scope='module') and dependent tests declare depends=[...], so they are automatically skipped when a prerequisite fails
  • Each legacy file is split into individual def test_*() functions (one per closure) so failures are isolated rather than aborting the whole file
  • Adds pytest-dependency==0.6.1 to requirements.txt and registers it in rspy/pytest/plugins.py for fast-fail on missing install
  • Updates .github/skills/pytest-infra.md with the on_fail=test.ABORT migration pattern

Files migrated

Legacy Pytest Context
test-out-of-range-throw.py pytest-out-of-range-throw.py nightly
test-timestamp-domain.py pytest-timestamp-domain.py nightly
test-options-watcher.py pytest-options-watcher.py nightly
test-advanced-mode.py pytest-advanced-mode.py nightly
test-presets.py pytest-presets.py nightly
test-drops-on-set.py pytest-drops-on-set.py nightly
test-rgb-options-metadata-consistency.py pytest-rgb-options-metadata-consistency.py nightly
test-set-gain-stress-test.py pytest-set-gain-stress-test.py weekly
test-uvc-power-stress-test.py pytest-uvc-power-stress-test.py weekly

Test plan

  • All nightly tests run locally and pass against D455
  • pytest-set-gain-stress-test verified locally (weekly)
  • pytest-uvc-power-stress-test verified locally (weekly, 33s)
  • Infra regression tests (unit-tests/infra-tests/) -- 85/85 passed

OhadMeir and others added 10 commits April 29, 2026 11:42
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Use @pytest.mark.dependency(scope='module') for the two prerequisite
tests (advanced_mode_support, visual_preset_support) so that all
subsequent tests are automatically skipped when a prerequisite fails,
matching the legacy on_fail=test.ABORT behavior.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Split into 3 test functions: test_laser_power_frame_drops,
test_depth_options_frame_drops, test_color_options_frame_drops.
FrameDropChecker class replaces inline callback logic.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Single test function verifying get_option and frame metadata agree
for all color options at min/max/default values.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Single weekly stress test verifying no exception is thrown when
setting PU (gain) option repeatedly [RSDSO-17185].

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Single weekly stress test for UVC power locking: multiple threads
setting visual presets concurrently while GVD commands are issued
in parallel. No exceptions should be thrown.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@OhadMeir
OhadMeir marked this pull request as ready for review April 29, 2026 08:47
Copilot AI review requested due to automatic review settings April 29, 2026 08:47

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

Migrates the unit-tests/live/options/ live device option tests from the legacy rspy.test framework to pytest, introducing pytest-dependency to preserve legacy on_fail=test.ABORT semantics and updating infra/docs to support the new patterns.

Changes:

  • Converted 9 legacy test-*.py scripts into 9 pytest-*.py modules with def test_*() granularity and (where needed) dependency-based skipping.
  • Added pytest-dependency to unit test requirements and to the required-plugin availability check.
  • Added a device_in_service_mode fixture to replace legacy wrapper behavior for D585S service mode and documented the ABORT migration pattern.

Reviewed changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
unit-tests/requirements.txt Adds pytest-dependency dependency for ABORT-style prerequisite skipping.
unit-tests/py/rspy/pytest/plugins.py Registers pytest_dependency as a required plugin for fail-fast missing installs.
unit-tests/conftest.py Adds device_in_service_mode fixture (D585S service mode handling).
.github/skills/pytest-infra.md Documents on_fail=test.ABORT → pytest-dependency migration pattern.
unit-tests/live/options/test-uvc-power-stress-test.py Removes legacy rspy.test version of the weekly UVC power stress test.
unit-tests/live/options/test-timestamp-domain.py Removes legacy timestamp domain test.
unit-tests/live/options/test-set-gain-stress-test.py Removes legacy gain stress test.
unit-tests/live/options/test-rgb-options-metadata-consistency.py Removes legacy RGB options/metadata consistency test.
unit-tests/live/options/test-presets.py Removes legacy presets test.
unit-tests/live/options/test-out-of-range-throw.py Removes legacy out-of-range exception test.
unit-tests/live/options/test-options-watcher.py Removes legacy options watcher test.
unit-tests/live/options/test-drops-on-set.py Removes legacy frame-drop-on-set test.
unit-tests/live/options/test-advanced-mode.py Removes legacy advanced mode test.
unit-tests/live/options/pytest-uvc-power-stress-test.py Adds pytest version of weekly UVC locking stress test (threads + GVD).
unit-tests/live/options/pytest-timestamp-domain.py Adds pytest version of nightly timestamp domain test split into 4 cases.
unit-tests/live/options/pytest-set-gain-stress-test.py Adds pytest version of weekly gain stress test using device_in_service_mode.
unit-tests/live/options/pytest-rgb-options-metadata-consistency.py Adds pytest version of nightly RGB option vs metadata consistency test.
unit-tests/live/options/pytest-presets.py Adds pytest version of nightly presets test with dependency-based prerequisites.
unit-tests/live/options/pytest-out-of-range-throw.py Adds pytest version of out-of-range exception test using pytest.raises.
unit-tests/live/options/pytest-options-watcher.py Adds pytest version of nightly options watcher test split into multiple tests.
unit-tests/live/options/pytest-drops-on-set.py Adds pytest version of nightly “drops on set” tests with callback-based checker.
unit-tests/live/options/pytest-advanced-mode.py Adds pytest version of nightly advanced mode test split into dependency-gated cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@OhadMeir
OhadMeir requested a review from Nir-Az April 29, 2026 11:04
@OhadMeir
OhadMeir force-pushed the unit-tests branch 2 times, most recently from 11cc009 to 38a9841 Compare April 30, 2026 05:50
Comment thread unit-tests/conftest.py Resolved
@OhadMeir

Copy link
Copy Markdown
Contributor Author

CI running all migrated tests (including weekly context) LRS_libci_pipeline/15318/

def make_callback(get_sensor):
"""Return a (callback, count) pair. get_sensor() returns the current sensor,
used to skip read-only options (e.g. temperature) that may change spuriously."""
count = [0]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

a bit hard to follow the count[0] , count[1] around.
Can you make it clearer?
Any reason for the small refactor?
Note that migration should be done as is with small diff unless a BUG is found.
Make the review simpler and if the test starts failing we know to distinguish between migration issue or refactor issue
So far I see a refactor 2/2 files I reviewed, will keep reviewing

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

From my conversion conversation with Clode:
"each test will do its own sensor setup so the callback counter starts clean, avoiding the shared-state problem"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I will check if a simple counter can be used instead of a list

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

As discussed, using a global counter like before. I have created a helper function that setup the sensor and callback and it also zero the counter for each test.


def check_option_and_metadata_values(color_sensor, option, metadata, value_to_set, frame):
changed = color_sensor.get_option(option)
assert changed == value_to_set, f"Option {option}: expected {value_to_set}, got {changed}"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since this function is called in some kind of loop better to replace assert with check.equal
It will keep going after the first failure and fail at the end with all the failures and we get a full picture

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

@Nir-Az Nir-Az left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Great migration

@Nir-Az
Nir-Az merged commit 8aec9b6 into realsenseai:development May 3, 2026
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