Test Markers
RTMX provides pytest markers to link tests directly to requirements, enabling automatic traceability tracking.
Basic Usage
Section titled “Basic Usage”import pytest
@pytest.mark.req("REQ-AUTH-001")@pytest.mark.scope_unitdef test_oauth_login(): """Validates REQ-AUTH-001: OAuth 2.0 authentication.""" assert authenticate_user(token) == expected_userAvailable Markers
Section titled “Available Markers”Requirement Link
Section titled “Requirement Link”| Marker | Purpose |
|---|---|
@pytest.mark.req("REQ-XXX-NNN") | Links test to requirement |
The requirement ID must match a row in your RTM database.
Scope Markers
Section titled “Scope Markers”| Marker | Purpose |
|---|---|
@pytest.mark.scope_unit | Unit test scope |
@pytest.mark.scope_integration | Integration test scope |
@pytest.mark.scope_system | System/E2E test scope |
Technique Markers
Section titled “Technique Markers”| Marker | Purpose |
|---|---|
@pytest.mark.technique_nominal | Nominal/happy path testing |
@pytest.mark.technique_parametric | Parametric testing |
@pytest.mark.technique_monte_carlo | Monte Carlo testing |
@pytest.mark.technique_stress | Stress testing |
Environment Markers
Section titled “Environment Markers”| Marker | Purpose |
|---|---|
@pytest.mark.env_simulation | Simulation environment |
@pytest.mark.env_hil | Hardware-in-the-loop |
@pytest.mark.env_anechoic | Anechoic chamber |
@pytest.mark.env_field | Field testing |
Configuration
Section titled “Configuration”Enable markers in rtmx.yaml:
rtmx: pytest: marker_prefix: "req" register_markers: trueOr 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",]Scanning Tests
Section titled “Scanning Tests”Update your RTM database from test markers:
rtmx from-tests # Scan and display resultsrtmx from-tests --update # Update RTM databasertmx from-tests --dry-run # Preview changesBest Practices
Section titled “Best Practices”One Test Per Requirement
Section titled “One Test Per Requirement”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.""" passDescriptive Docstrings
Section titled “Descriptive Docstrings”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. """ passMultiple Requirements
Section titled “Multiple Requirements”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.""" passCI Integration
Section titled “CI Integration”Check for unmarked tests in CI:
# Fail if tests don't have required markerspytest --strict-markers
# Report marker coveragertmx from-tests --report