Write pytests
If you are new to pytest, I recommend you to learn pytest without the complexity of Octoprobe.
Just start with the examples from https://docs.pytest.org/en/stable/how-to/index.html.
You might be interested in
fixtures
test collection (
--collect-only)How to read pytest output (specially the
-sflag.)The pytest explorer in VSCode
How to debug pytests in VSCode
Setup and Teardown
The hardware has to be prepared for the tests. This is done by pytest before/after entering the tests.
For the example below, two MCU tentacles with PYBv1.1 and Pico are connected and started with this command:
pytest tests/test_simple.py::test_i2c tests/test_simple.py::test_onewire
References to to source code
Sessions setup: pytest fixture
Sessions setup: Build the software
- ArgsFirmware.build_firmware()[source]
Build the firmware and update ‘tentacle.tentacle_state.firmware_spec’.
Session setup: Install the firmware
- CtxTestRun.function_prepare_dut()[source]
- CtxTestRun.function_setup_dut_flash()[source]
Function setup: pytest fixture
- tests.conftest.setup_tentacles()[source]
Runs setup and teardown for every single test:
Setup
powercycle the tentacles
Turns on the ‘active’ LED on the tentacles involved
Flash firmware
Set the relays according to @pytest.mark.required_futs(EnumFut.FUT_I2C).
yields to the test function
Teardown
Resets the relays.
- Parameters:
testrun (CtxTestRun) – The structure created by testrun()
Function setup: Set the relays
The test functions
- tests.test_simple.test_i2c()[source]
- tests.test_simple.test_onewire()[source]
Comments to above sequence diagram
SESSION setup
Will install the firmware and will power off all tentacles.
FUNCTION setup:
Will power on the required tentacle.
Close the relais for the required tentalces.
Set the blue LED on.
FUNCTION teardown:
Will power down the required tentacle.
Open the relais for the required tentalces.
Set the blue LED off.