Running Tests
Tessera has a full pytest suite targeting 100% coverage across all application code. Tests live in the tests/ directory with one file per module. This page covers how to run the suite, how to read the output, and what the coverage targets are.
Prerequisites
Dev dependencies must be installed. If you haven't already:
pip install -e .[dev]This installs pytest, pytest-cov, and qiskit-aer alongside the runtime dependencies.
Running the Suite
Full suite with coverage report:
pytest tests/ --cov=. --cov-report=term-missingFull suite without coverage:
pytest tests/Single test file:
pytest tests/test_converters.py --cov=. --cov-report=term-missingHTML coverage report:
pytest tests/ --cov=. --cov-report=htmlOpens htmlcov/index.html in your browser for a full visual breakdown per file.
Understanding the Output
Test results:
tests/test_converters.py ..... [ 43%].: passing testF: failing testE: test errored out (unexpected exception)- The percentage shows overall progress through the suite
Coverage table:
Name Stmts Miss Cover Missing
-----------------------------------------------------
tessera/converters.py 28 1 96% 19Stmts: total executable lines in the fileMiss: lines not executed during testsCover: percentage of lines coveredMissing: specific line numbers not covered
Coverage Targets
The target is 100% coverage across all application code. The one known and expected exception is noted below.
| File | Target | Notes |
|---|---|---|
circuit.py | 100% | |
instruction.py | 100% | |
gate_library.py | 100% | |
converters.py | 100% | |
pass_manager.py | 100% | |
transpiler.py | 100% | |
transpiler_pass.py | 89% | Abstract method miss is expected: see below |
hardware/coupling_map.py | 100% | |
api/transpile.py | 100% | |
backends/basis_gate_sets.py | 100% | |
backends/decomposition_maps.py | 100% | |
backends/backend_registry.py | 100% | |
passes/basis_translation_pass.py | 100% | |
passes/dense_layout_pass.py | 100% | |
passes/basic_swap_router.py | 100% | |
passes/remove_barriers_pass.py | 100% | |
passes/cancel_adjacent_pass.py | 100% | |
passes/merge_rotations_pass.py | 100% | |
passes/trivial_pass.py | 100% | |
passes/identity_pass.py | 100% | |
test.py | 0% | This file is itself a test script, so there is no need to test it |
What to Ignore
transpiler_pass.py line 24: the pass statement inside the abstract run() method. Subclasses always override it so it is never executed by design. The 89% coverage on this file is expected and can be ignored.
Test files themselves: coverage on test files will always show 100% and can be ignored. They are not application code.
Adding Tests for New Code
When you add a new pass or module, create a corresponding test_<module_name>.py in tests/. At minimum cover:
- Happy path: expected transformation occurs
- No-op case: circuit that should not change stays unchanged
- Edge cases: empty circuit, single instruction, measurements only
- Any exceptions the code raises
See Adding a Pass or Adding a Backend for specific test patterns for each.