Skip to main content
FixturFab

Technical Reference

Technical reference information for the pytest-f3ts plugin, including source code documentation and API details.

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:

ModuleDescription
pytest_f3tsMain package entry point
pytest_f3ts.fixturesTest fixtures for hardware access
pytest_f3ts.pluginPytest plugin hooks and configuration
pytest_f3ts.runner_clientTest Runner communication client
pytest_f3ts.utilsUtility functions

Schema Modules#

Data validation and serialization schemas:

Schema ModuleDescription
pytest_f3ts.schemas.attachmentFile attachment schemas
pytest_f3ts.schemas.caseTest case schemas
pytest_f3ts.schemas.commitResult commit schemas
pytest_f3ts.schemas.configConfiguration schemas
pytest_f3ts.schemas.limitsTest limit schemas
pytest_f3ts.schemas.msgMessage schemas
pytest_f3ts.schemas.planTest plan schemas
pytest_f3ts.schemas.resultTest result schemas
pytest_f3ts.schemas.runTest run schemas
pytest_f3ts.schemas.tokenAuthentication 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:

MethodDescription
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:

MethodDescription
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 response

Methods:

MethodDescription
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#

OptionDescription
--hardware-config=FILEPath to hardware configuration YAML
--no-hardwareSkip tests marked with @pytest.mark.hardware
--validate-configValidate configuration without running tests
--report-format=FORMATOutput format: json, csv, xml
--report-path=PATHDirectory 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
        }
      ]
    }
  ]
}

Next Steps#

  • Examples - See these APIs in action
  • Messaging - Communication architecture with Test Runner
Last updated:January 25, 2025