How this all ties up with the final screen of QGIS Plugin Builder once we activate the
Unit Tests checkbox? Where to start when we want to unit test the developed plugins?
Here is a sample test that checks that a layer has been added to the project:
def test_plugin(qgis_countries_layer): project = QgsProject.instance() project.addMapLayer(qgis_countries_layer) assert project.count() == 1 assert project.mapLayersByName(qgis_countries_layer.name()) == [qgis_countries_layer]
Since pytest is not part of the Python standard library, it is suggested that you create a virtual environment for running the tests:
python -m venv --system-site-packages .venv
pip install pytest-qgis
- Finally run
pytestto run the test(s)
Disclaimer: I am one of the authors of pytest-qgis.