Skip to content

conftest.py

fixtur-ctrl-func-test.conftest

pytest configuration for the FixturFab FixturCtrl Test Fixture.

logger = logging.getLogger(__name__) module-attribute

pytest_addoption

Pytest hook for adding additional command line arguments.

Source code in test_plans/fixtur-ctrl-func-test/conftest.py
16
17
18
19
20
21
22
23
def pytest_addoption(parser):
    """Pytest hook for adding additional command line arguments."""
    parser.addoption(
        "--skip-prog",
        action="store_true",
        default=False,
        help="mark to skip programming test",
    )

pytest_collection_modifyitems

Pytest hook that runs at test collection.

Source code in test_plans/fixtur-ctrl-func-test/conftest.py
26
27
28
29
30
31
32
33
34
def pytest_collection_modifyitems(config, items):
    """Pytest hook that runs at test collection."""
    if not config.getoption("--skip-prog"):
        return

    skip_slow = pytest.mark.skip(reason="skip if --skip-prog option to run")
    for item in items:
        if "prog" in item.keywords:
            item.add_marker(skip_slow)

delays

Pytest fixture that holds the delay configuration information.

Source code in test_plans/fixtur-ctrl-func-test/conftest.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
@pytest.fixture(scope="session")
def delays(fixture_config, backend_api):
    """Pytest fixture that holds the delay configuration information."""
    try:
        delays = Delays(fixture_config)

    except Exception as error:
        if backend_api:
            notif = Dialog(title="ERROR: Setup Error", message=str(error))
            logger.info(f"-> sending error notification to backend {notif}")
            response = backend_api.send_user_notif(notif)
            logger.info(f"-> backend api response: {response}")
        raise error

    yield delays

find_device_by_serial

Source code in test_plans/fixtur-ctrl-func-test/conftest.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
def find_device_by_serial(serial, check_if=True):
    output = subprocess.check_output(["/usr/src/scripts/idusb.sh"]).decode("utf-8")
    # print(output)
    devices = output.split("\n")
    for device in devices:
        if device:
            data = device.split(" -- ")
            port = data[0]
            fields = data[1].split(", ")
            for field in fields:
                if field.split(": ")[0] == "Serial":
                    if check_if:
                        if field.split(": ")[1] == serial:
                            print(output)
                            return port
                    else:
                        if field.split(": ")[1] != serial:
                            print(output)
                            return port

fixtur_cntl

Pytest Fixture for communicating with the DUT.

Source code in test_plans/fixtur-ctrl-func-test/conftest.py
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
@pytest.fixture(scope="session")
def fixtur_cntl(backend_api, fixture_config):
    """Pytest Fixture for communicating with the DUT."""
    baud = int(fixture_config.user_vars["SERIAL_BAUD"])
    timeout = float(fixture_config.user_vars["SERIAL_TIMEOUT"])
    ffc_sn = str(fixture_config.user_vars["FIXT_FFC_SERIAL"])
    port = find_device_by_serial(ffc_sn)

    try:
        serial = FixturCNTL(port=port, baud=baud, timeout=timeout)
        serial.open()
    except Exception as error:
        if backend_api:
            notif = Dialog(
                title="ERROR: DUT Serial Interface Setup Error", message=str(error)
            )
            logger.info(f"-> sending error notification to backend {notif}")
            response = backend_api.send_user_notif(notif)
            logger.info(f"-> backend api response: {response}")
        raise error

    yield serial

    logger.debug("Closing test fixture interface")
    serial.close()
    logger.debug("-> CLOSED")

dut_serial

Pytest Fixture for communicating with the DUT.

Source code in test_plans/fixtur-ctrl-func-test/conftest.py
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
@pytest.fixture(scope="session")
def dut_serial(backend_api, fixture_config):
    """Pytest Fixture for communicating with the DUT."""
    baud = int(fixture_config.user_vars["SERIAL_BAUD"])
    timeout = float(fixture_config.user_vars["SERIAL_TIMEOUT"])
    ffc_sn = str(fixture_config.user_vars["FIXT_FFC_SERIAL"])
    port = find_device_by_serial(
        ffc_sn, check_if=False
    )  # Get port of FFC not in Fixture Base (DUT)

    try:
        dut_serial = FixturCNTL(port=port, baud=baud, timeout=timeout)

    except Exception as error:
        if backend_api:
            notif = Dialog(
                title="ERROR: DUT Serial Interface Setup Error", message=str(error)
            )
            logger.info(f"-> sending error notification to backend {notif}")
            response = backend_api.send_user_notif(notif)
            logger.info(f"-> backend api response: {response}")
        raise error

    yield dut_serial

    logger.debug("Closing test fixture interface")
    dut_serial.close()
    logger.debug("-> CLOSED")

test_fixture

Pytest Fixture for communicating with all fixture hardware.

Connects with the instrumentation, DUT, and control board within the FixturCtrl Functional Test Fixture.

Source code in test_plans/fixtur-ctrl-func-test/conftest.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
@pytest.fixture(scope="session")
def test_fixture(fixture_config, backend_api):
    """Pytest Fixture for communicating with all fixture hardware.

    Connects with the instrumentation, DUT, and control board within
    the FixturCtrl Functional Test Fixture.
    """
    try:
        fixture_interface = FixtureInterface(fixture_config)

    except Exception as error:
        if backend_api:
            notif = Dialog(title="ERROR: Fixture Setup Error", message=str(error))
            logger.info(f"-> sending error notification to backend {notif}")
            response = backend_api.send_user_notif(notif)
            logger.info(f"-> backend api response: {response}")
        raise error

    yield fixture_interface

    logger.debug("Closing test fixture interface")
    fixture_interface.close()
    logger.debug("-> CLOSED")