agentleFS
realsenseairealsenseai/librealsense/.claude/skills/pytest-infra/SKILL.md

pytest-infra

Skill9.1k starsChanged 27 days agoApache-2.0View on GitHub

Write a new librealsense pytest test (pytest-*.py) - markers, fixtures, assertions, FW gating, temp files - or change the pytest infrastructure (conftest.py, rspy/pytest). Use before adding a Python test or modifying conftest.py / rspy.

Trending

Steady talk.about the whole repository

Dec 2025: 1 mentionJan 2026: 3 mentionsFeb 2026: 1 mentionMar 2026: 1 mentionApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 3 mentionsJul 2026: 5 mentionsAug 2026: 6 mentionsSep 2026: 6 mentionsOct 2026: 6 mentionsNov 2026: 2 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the realsenseai/librealsense repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about realsenseai/librealsense

The biggest 5 of 34 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 34

Talked about on GitHub (34 times).

On GitHub · 34

29 more on GitHub

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    All Python tests run under pytest.

    line 13
  2. Very specific:

    Location and name: put the file in the matching topic directory (e.g.

    line 29
  3. Very specific:

    Don't add pytest.mark.live.

    line 47
  4. Very specific:

    Don't wrap the test in try/except.

    line 67

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Pytest Tests & Infrastructure

When to Use This Skill

  • Adding a new Python test (pytest-*.py) under unit-tests/
  • Modifying pytest infrastructure (conftest.py, py/rspy/pytest/, py/rspy/devices.py, hub modules)

All Python tests run under pytest. run-unit-tests.py is kept only for C++ tests (see the testing skill).

Key Files

FilePurpose
unit-tests/conftest.pyHooks, fixtures, CLI flags, marker registration, default 200s timeout
py/rspy/pytest/device_helpers.pyDevice parametrization (device_each), require_min_fw_version
py/rspy/pytest/collection.pyCollection filtering: context gating, --live, priority ordering
py/rspy/pytest/logging_setup.pyPer-test log files, terminal summary
py/rspy/pytest/cli.pyLegacy CLI flag translation (e.g. -r → -k)
py/rspy/pytest/plugins.pyRequired pytest plugin registry
py/rspy/devices.pyDevice discovery, hub port control (enable_only())

Adding a New Test

  1. Location and name: put the file in the matching topic directory (e.g. unit-tests/live/frames/) named pytest-<name>.py. Start with the copyright header (current year).
  2. Pick markers (module-level pytestmark = [...] or per test):

    NeedMarker
    Any one matching devicepytest.mark.device("D400*")
    Run once per matching devicepytest.mark.device_each("D400*")
    Each device matching any of several patternspytest.mark.device_each("D555", "D585")
    Several devices at once (with test_devices)pytest.mark.device("D400*", "D500*")
    Exclude SKUspytest.mark.device_exclude("D401")
    Only / never on a connection typepytest.mark.device_type("GMSL") / pytest.mark.device_type_exclude("DDS")
    Nightly / weekly onlypytest.mark.context("nightly")
    Needs a DDS buildpytest.mark.dds
    Run earlier / later (default 500)pytest.mark.priority(100)
    Longer than the 200s defaultpytest.mark.timeout(600)
    Known flakypytest.mark.flaky(reruns=2) — reruns=, never retries= (silently ignored, guarded by an infra test)
    • Exclude unsupported SKUs/transports with markers so they are skipped at collection — don't pytest.skip() at runtime for that.
    • Don't add pytest.mark.live; --live filtering is derived from the device markers.
    • A new custom marker must be registered in conftest.py:pytest_configure.
  3. Pick the lowest fixture you need:

    You needFixture
    Device + contexttest_device → (dev, ctx)
    D585S in service mode (no-op for others)test_device_wrapped
    Several devicestest_devices → ([dev, ...], ctx)
    Only a contexttest_context
    Hub setup only, own context (e.g. DDS settings)module_device_setup
    Active --context tagstest_context_var
    No devicenone

    The first test in a file recycles the device via the hub; later tests in the file reuse it.

  4. Write the test body:
    • Logging: import logging; log = logging.getLogger(__name__).
    • Hard stop: assert. To keep looping and report every failure: from pytest_check import check (check.equal, check.is_true, check.almost_equal(a, b, abs=tol)).
    • Minimum FW: require_min_fw_version(dev, rsutils.version(5, 15, 0, 0), "FEATURE") from rspy.pytest.device_helpers — no inline version checks.
    • Files written by the test go under the tmp_path fixture, never tempfile.mkdtemp().
    • Don't wrap the test in try/except; let pytest report the exception. Expected exceptions: with pytest.raises(...). Test-scoped cleanup: a yield fixture. If you must catch, keep the original error (raise or pytest.fail(f"...: {e}")), never except: pass.
    • Reuse helpers (rspy.snippets, rspy.pytest.device_helpers) before writing new ones. Helper module names must be unique across unit-tests/ (pytest imports all of them in one process).
    • A test that depends on an earlier one: the earlier test sets a flag in a module-level dict, dependents pytest.skip() when it's missing.
  5. Run it locally from unit-tests/: python -m pytest -v live/frames/pytest-<name>.py. Don't use -s when you need the per-test log files.

Minimal example

# License: Apache 2.0. See LICENSE file in root directory.
# Copyright(c) <current year> RealSense, Inc. All Rights Reserved.

import pytest
import pyrealsense2 as rs
import logging
log = logging.getLogger(__name__)

pytestmark = [pytest.mark.device_each("D400*")]

def test_depth_streaming(test_device):
    dev, ctx = test_device
    pipe = rs.pipeline(ctx)
    cfg = rs.config()
    cfg.enable_stream(rs.stream.depth, rs.format.z16, 30)
    pipe.start(cfg)
    try:
        frames = pipe.wait_for_frames()
    finally:
        pipe.stop()
    assert frames.size() > 0

Changing the Infrastructure

  • Infra regression tests live in unit-tests/infra-tests/. They mock the hardware (no camera or pyrealsense2 needed) and run on GHA for every PR. Every change to conftest.py or py/rspy/pytest/*.py must pass python -m pytest infra-tests/ -v (from unit-tests/), and every new infra feature (marker, CLI flag, skip/fail rule) needs a test there. test_e2e_*.py files run real pytest subprocesses against the real conftest.py via infra-tests/helpers.py:run_e2e().
  • New pytest plugin: pin it in unit-tests/requirements.txt and add it to REQUIRED_PYTEST_PLUGINS in py/rspy/pytest/plugins.py. A missing plugin otherwise silently disables its CLI options; the registry makes pytest_configure fail loudly.
  • Hub ports: CombinedHub numbers ports across hubs (Acroname first, then UniFi). devices.enable_only() derives the enabled ports on every call — don't add a cache.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.