Skip to content

Test Markers

RTMX provides pytest markers to link tests directly to requirements, enabling automatic traceability tracking.

import pytest
@pytest.mark.req("REQ-AUTH-001")
@pytest.mark.scope_unit
def test_oauth_login():
"""Validates REQ-AUTH-001: OAuth 2.0 authentication."""
assert authenticate_user(token) == expected_user
MarkerPurpose
@pytest.mark.req("REQ-XXX-NNN")Links test to requirement

The requirement ID must match a row in your RTM database.

MarkerPurpose
@pytest.mark.scope_unitUnit test scope
@pytest.mark.scope_integrationIntegration test scope
@pytest.mark.scope_systemSystem/E2E test scope
MarkerPurpose
@pytest.mark.technique_nominalNominal/happy path testing
@pytest.mark.technique_parametricParametric testing
@pytest.mark.technique_monte_carloMonte Carlo testing
@pytest.mark.technique_stressStress testing
MarkerPurpose
@pytest.mark.env_simulationSimulation environment
@pytest.mark.env_hilHardware-in-the-loop
@pytest.mark.env_anechoicAnechoic chamber
@pytest.mark.env_fieldField testing

Enable markers in rtmx.yaml:

rtmx:
pytest:
marker_prefix: "req"
register_markers: true

Or in pyproject.toml:

[tool.pytest.ini_options]
markers = [
"req(id): Link test to requirement",
"scope_unit: Unit test scope",
"scope_integration: Integration test scope",
"scope_system: System test scope",
]

Update your RTM database from test markers:

rtmx from-tests # Scan and display results
rtmx from-tests --update # Update RTM database
rtmx from-tests --dry-run # Preview changes

Each requirement should have at least one test:

@pytest.mark.req("REQ-AUTH-001")
def test_login_success():
"""Happy path test for REQ-AUTH-001."""
pass
@pytest.mark.req("REQ-AUTH-001")
def test_login_invalid_token():
"""Error handling for REQ-AUTH-001."""
pass

Include the requirement ID in docstrings for clarity:

@pytest.mark.req("REQ-DATA-003")
def test_export_csv():
"""REQ-DATA-003: Export data as CSV.
Validates that users can export their data in CSV format
with proper encoding and column headers.
"""
pass

A test can validate multiple requirements:

@pytest.mark.req("REQ-AUTH-001")
@pytest.mark.req("REQ-AUDIT-002")
def test_login_audit():
"""Validates login and audit logging."""
pass

Check for unmarked tests in CI:

# Fail if tests don't have required markers
pytest --strict-markers
# Report marker coverage
rtmx from-tests --report