GispoCoding / pytest-qgis

A pytest plugin for testing QGIS python plugins
GNU General Public License v2.0
30 stars 8 forks source link

pytest-qgis

PyPI version Downloads CI Code on Github Ruff pre-commit codecov.io

A pytest plugin for testing QGIS python plugins.

Features

This plugin makes it easier to write QGIS plugin tests with the help of some fixtures and hooks:

Fixtures

Markers

Check the marker api documentation and examples for the ways markers can be used.

Hooks

Utility tools

Command line options

ini-options

QgisBot

Class to hold common utility methods for interacting with QGIS. Check test_qgis_bot.py for usage examples. Here are some of the methods:

Requirements

This pytest plugin requires QGIS >= 3.16 to work though it might work with older versions.

Installation

Install with pip:

pip install pytest-qgis

Development environment

# Create a virtual environment with qgis and dependencies available
$ python -m venv .venv --system-site-packages
# Activate the virtual environment
$ source .venv/bin/activate
# Update pip and setuptools
$ python -m pip install -U pip setuptools
$ pip install pip-tools
# Install dependencies
$ pip-sync requirements.txt requirements-dev.txt
# Install pre-commit hooks
$ pre-commit install

Updating dependencies

  1. pip-compile --upgrade
  2. pip-compile --upgrade requirements-dev.in

Contributing

Contributions are very welcome.

License

Distributed under the terms of the GNU GPL v2.0 license, "pytest-qgis" is free and open source software.