This section contains technical reference information for the pytest-f3ts plugin.
Source Code#
The source code for the pytest-f3ts plugin is available on GitLab. Generated docstrings can be viewed by selecting the module/file you are interested in from the sidebar.
Module Reference#
The pytest-f3ts package is organized into the following modules:
| Module | Description |
|---|---|
pytest_f3ts | Main package entry point |
pytest_f3ts.fixtures | Test fixtures for hardware access |
pytest_f3ts.plugin | Pytest plugin hooks and configuration |
pytest_f3ts.runner_client | Test Runner communication client |
pytest_f3ts.utils | Utility functions |
Schema Modules#
Data validation and serialization schemas:
| Schema Module | Description |
|---|---|
pytest_f3ts.schemas.attachment | File attachment schemas |
pytest_f3ts.schemas.case | Test case schemas |
pytest_f3ts.schemas.commit | Result commit schemas |
pytest_f3ts.schemas.config | Configuration schemas |
pytest_f3ts.schemas.limits | Test limit schemas |
pytest_f3ts.schemas.msg | Message schemas |
pytest_f3ts.schemas.plan | Test plan schemas |
pytest_f3ts.schemas.result | Test result schemas |
pytest_f3ts.schemas.run | Test run schemas |
pytest_f3ts.schemas.token | Authentication token schemas |
Fixtures#
hardware_fixture#
The primary fixture for accessing hardware resources. Provides instrument access and lifecycle management.
def test_example(hardware_fixture):
ps = hardware_fixture.get_instrument("power_supply")
dmm = hardware_fixture.get_instrument("dmm")Methods:
| Method | Description |
|---|---|
get_instrument(name) | Returns configured instrument by name |
get_signal(name) | Returns signal connection by logical name |
get_fixture_info() | Returns fixture metadata dict |
measure#
Fixture for recording measurements alongside test results.
def test_voltage(power_supply, measure):
voltage = power_supply.measure_voltage()
measure.record("output_voltage", voltage, unit="V", limits=(3.2, 3.4))Methods:
| Method | Description |
|---|---|
record(name, value, unit=None, limits=None) | Record a measurement |
record_pass(name, message=None) | Record a pass condition |
record_fail(name, message=None) | Record a fail condition |
get_measurements() | Returns all recorded measurements |
Parameters for record():
name: Measurement identifier (string)value: Measured value (number or string)unit: Optional unit string (e.g., "V", "A", "ms")limits: Optional tuple of (min, max) for limit checking
dut_serial#
Convenience fixture for serial communication with the device under test.
def test_serial_response(dut_serial):
dut_serial.write(b"VERSION\n")
response = dut_serial.read_until(b"\n", timeout=2.0)
assert b"v1.2" in responseMethods:
| Method | Description |
|---|---|
write(data) | Write bytes to serial port |
read(size) | Read specified number of bytes |
read_until(terminator, timeout=None) | Read until terminator or timeout |
flush() | Flush input and output buffers |
Markers#
@pytest.mark.hardware#
Mark tests that require hardware. These tests are skipped when --no-hardware is passed.
@pytest.mark.hardware
def test_requires_fixture():
...@pytest.mark.parametric#
Mark parametric tests (measurements within limits).
@pytest.mark.parametric
def test_voltage_in_range(measure, dmm):
voltage = dmm.measure_voltage()
measure.record("vcc", voltage, limits=(3.2, 3.4))@pytest.mark.functional#
Mark functional tests (pass/fail outcomes).
@pytest.mark.functional
def test_led_blinks(dut_serial):
dut_serial.write(b"BLINK\n")
assert dut_serial.read_until(b"OK")@pytest.mark.calibration#
Mark calibration routines (typically run separately from production tests).
@pytest.mark.calibration
def test_adc_calibration(dut_serial, measure):
# Calibration procedure
...@pytest.mark.requires_instrument#
Skip test if specified instrument is not available.
@pytest.mark.requires_instrument("oscilloscope")
def test_signal_timing():
...@pytest.mark.retry#
Automatically retry flaky tests.
@pytest.mark.retry(count=3, delay=1.0)
def test_intermittent_connection():
...Command Line Options#
| Option | Description |
|---|---|
--hardware-config=FILE | Path to hardware configuration YAML |
--no-hardware | Skip tests marked with @pytest.mark.hardware |
--validate-config | Validate configuration without running tests |
--report-format=FORMAT | Output format: json, csv, xml |
--report-path=PATH | Directory for test reports |
Configuration API#
HardwareConfig#
Programmatic access to configuration:
from pytest_f3ts import HardwareConfig
config = HardwareConfig.from_file("hardware_config.yaml")
print(config.instruments)
print(config.fixture_info)InstrumentRegistry#
Register custom instrument drivers:
from pytest_f3ts import InstrumentRegistry
@InstrumentRegistry.register("custom_psu")
class CustomPowerSupply:
def __init__(self, connection, settings=None):
...
def set_voltage(self, voltage):
...
def measure_current(self):
...Report Structure#
JSON report format:
{
"test_session": {
"start_time": "2025-01-10T14:30:00Z",
"end_time": "2025-01-10T14:32:15Z",
"fixture": {
"name": "Production Test Fixture v2",
"serial_number": "FTF-2024-0042"
}
},
"tests": [
{
"name": "test_voltage_in_range",
"outcome": "passed",
"duration": 1.234,
"measurements": [
{
"name": "vcc",
"value": 3.31,
"unit": "V",
"limits": [3.2, 3.4],
"passed": true
}
]
}
]
}