openflexure-microscope-server/hardware-specific-tests
2025-07-29 18:42:15 +01:00
..
picamera2 Apply suggestions from code review of branch Camera-tweaks 2025-07-29 16:34:38 +00:00
README.md Improve README a for hardware specific tests, and make fixes to picamera_tests script 2025-07-29 18:42:15 +01:00

Hardware specific tests for the PiCamera.

These are very slow as they run on hardware. They can be run with:

pytest hardware-specific-tests

It is essential to stop the server first:

ofm stop

However, this will not archive the tests in the Git repository for reporting the coverage. For this see the section below on reporting the coverage.

When writing and debugging these unit tests it is often best to run a specific test and to use the -s flag to see the print statements. It is also often useful to use --pdb to drop you into a python debug session on any failure. For example, you might run:

pytest hardware-specific-tests/picamera2/test_exposure_time_drift.py::test_exposure_time_saves_and_loads -s --pdb

Reporting the coverage

To create a coverage report that will be included into the repository run:

./picamera_tests.py run

This will create a zip of test results along with hashes of the picamera files and the base camera file. The server will include this coverage report if the source files remain the same.

Creating a combined report locally

To create a combined coverage report locally (similar to the one created on CI) first run all normal tests with pytest.

Copy the .coverage file to .coverage.main

cp .coverage .coverage.main

Then run:

./picamera_tests.py unzip

to get the .coverage.picamera file.

To combine reports run:

coverage combine

It is then possible to run:

  • coverage report to get the in-terminal report of the coverage.
  • coverage html to get the HTML overview of covered lines.
  • coverage xml to get an XML report any software that may need it.