Last modified: January 09, 2023
Gamera does not contain its own unit testing framework, but instead uses the great pytest framework.
This document does not attempt to replicate the pytest documentation, and will only discuss Gamera-specific additions.
From the gamera/tests directory, run all the unit tests with the command:
pytest --tb=no
Alternatively, you can run an individual test, say test_graph.py with:
pytest --tb=no test_graph.py
In case of failures you can obtain more information by omitting the option "--tb=no".
If you only want to run a single test function from a unit test script, use the "keyword" option "-k", e.g.:
pytest -k test_glyphs_from_xml_gz test_xml.py
A new unit test, say test_mystuff.py, is added by the following steps:
import pytest
from gamera.core import *
init_gamera()
def test_something():
img = load_image("data/OneBit_generic.png")
assert img.myplugin(3) == 42
def test_wronginput():
def _fail(img):
img.myplugin("should only be numeric")
img = load_image("data/OneBit_generic.png")
pytest.raises(Exception, _fail, img)
For more details, see the pytest documentation.
The unit test in gamera/tests/test_plugins.py will load and run the doc_example functions of all plugins available in Gamera. Therefore, writing a unit test for a Gamera plugin is often as simple as writing a doc_example plugin with the function. This is explained in Writing Plugins: Documenting and unit-testing Plugin functions.