pytest Plugin#
pytest integration for requirements traceability.
Plugin Hooks#
- jamb.pytest_plugin.plugin.pytest_addoption(parser)[source]#
Register jamb command-line options with pytest.
Registers the following options:
--jamb,--jamb-fail-uncovered,--jamb-test-matrix,--jamb-trace-matrix, and--jamb-documents.
- jamb.pytest_plugin.plugin.pytest_configure(config)[source]#
Register the requirement marker and initialize the jamb collector plugin.
Registers the
requirementmarker for linking tests to requirement UIDs and creates aRequirementCollectorinstance when--jambis enabled.
- jamb.pytest_plugin.plugin.pytest_sessionfinish(session, exitstatus)[source]#
Generate reports and check coverage after the test session completes.
Generates test records matrix when
--jamb-test-matrixor thetest_matrix_outputconfig option is set. Generates traceability matrix when--jamb-trace-matrixor thetrace_matrix_outputconfig option is set. Sets the exit status to failure when--jamb-fail-uncoveredorfail_uncoveredin the config is enabled and any test spec items lack coverage.For all options, CLI flags take precedence over
[tool.jamb]config values, which take precedence over hardcoded defaults.
- jamb.pytest_plugin.plugin.jamb_log(request)[source]#
Fixture to log custom messages for the traceability matrix.
Example:
@pytest.mark.requirement("SRS001") def test_validation(jamb_log): jamb_log.note("Verified input validation with boundary values") assert validate_input(-1) is False
- Return type:
- Parameters:
request (FixtureRequest)
Collector#
- class jamb.pytest_plugin.collector.RequirementCollector[source]#
Collects test-to-requirement mappings during pytest execution.
- pytest_config#
The pytest configuration object.
- Type:
- jamb_config#
Loaded jamb configuration (
JambConfig).- Type:
- graph#
The traceability graph built from stored documents, or
Noneif loading failed.- Type:
TraceabilityGraph | None
- test_links#
Accumulated test-to-requirement links recorded during collection and execution.
- Type:
- unknown_items#
UIDs referenced in test markers that do not exist in the traceability graph.
- __init__(config)[source]#
Initialize the requirement collector.
Loads the jamb configuration and the traceability graph from the native storage layer.
- Parameters:
config (
Config) – The pytest configuration object.- Return type:
None
- pytest_collection_modifyitems(items)[source]#
Collect requirement markers from all test items.
Extracts requirement UIDs from markers on each test item and records them as
LinkedTestentries. Yields control for collection to complete first.
- pytest_runtest_makereport(item, call)[source]#
Record test outcomes, notes, test actions, and expected results.
Captures the test outcome and data from the
jamb_logfixture, including failure messages and skip reasons, and updates allLinkedTestentries for the test.
- get_coverage()[source]#
Build coverage report for all items in test documents.
- Returns:
dict[str,ItemCoverage] – A dict mapping item UIDs toItemCoverageobjects for items in the configured test documents.- Return type:
- all_test_items_covered()[source]#
Check if all normative items in test documents have test coverage.
When
require_all_passis enabled (the default), an item is only considered covered if it has linked tests and all of those tests passed.
- generate_test_records_matrix(path, output_format, tester_id='Unknown', software_version=None)[source]#
Generate test records matrix.
- Parameters:
- Return type:
- generate_trace_matrix(path, output_format, trace_from=None, include_ancestors=False)[source]#
Generate traceability matrix.
- Parameters:
path (
str) – The output file path for the generated matrix.output_format (
str) – The output format (html, markdown, json, csv, or xlsx).trace_from (
str|None) – Starting document prefix for trace matrix. If not provided, auto-detects the root document.include_ancestors (
bool) – Whether to include “Traces To” column.
- Return type:
Markers#
- jamb.pytest_plugin.markers.get_requirement_markers(item)[source]#
Extract requirement item UIDs from a test item’s markers.
Supports @pytest.mark.requirement(‘UT001’, ‘UT002’, …).
- Parameters:
item (
Item) – A pytest test item.- Returns:
list[str] – List of requirement item UIDs found in requirement markers. Duplicates within the same test are removed while preserving order.- Raises:
TypeError – If a marker argument is not a string.
ValueError – If a marker argument is empty or whitespace-only.
- Return type:
JambLog#
- class jamb.pytest_plugin.log.JambLog[source]#
Collector for custom test messages to include in traceability matrix.
Usage in tests:
@pytest.mark.requirement("SRS001") def test_something(jamb_log): jamb_log.note("Custom verification note") jamb_log.test_action("Entered valid credentials") jamb_log.expected_result("Login succeeds") result = do_something() jamb_log.actual_result(f"Got: {result}") assert something