Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurable options and visual map #5

Merged
merged 13 commits into from
Nov 25, 2021
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,6 @@ target/

# pyenv
.python-version
/tests/data/db.gpkg-shm
/tests/data/db.gpkg-wal
/tests/data/*.tif.aux.xml
10 changes: 0 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,3 @@ repos:
- flake8-annotations~=2.6.2
- flake8-qgis>=0.1.4
- flake8-pytest-style==1.5.0
- repo: https://github.com/jazzband/pip-tools
rev: 6.4.0
hooks:
- id: pip-compile
name: pip-compile setup.py
files: ^(setup\.py|requirements\.txt)$
- id: pip-compile
name: pip-compile requirements-dev.in
args: [requirements-dev.in]
files: ^requirements-dev\.(in|txt)$
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,62 @@ This plugin makes it easier to write QGIS plugin tests with the help of some fix
add stuff to [`QgsProject`](https://qgis.org/pyqgis/master/core/QgsProject.html).
* `qgis_processing` initializes the processing framework. This can be used when testing code that
calls `processing.run(...)`.
* `qgis_version` returns QGIS version number as integer.

### Markers

* `qgis_show_map` lets developer inspect the QGIS map visually at the teardown of the test. **NOTE**: This marker is
still experimental and layer order might differ if using layers with different coordinate systems. Full signature of
the marker is:
```python
@pytest.mark.qgis_show_map(timeout: int = 30, add_basemap: bool = False, zoom_to_common_extent: bool = True, extent: QgsRectangle = None)
```
* `timeout` is the time in seconds until the map is closed.
* `add_basemap` when set to True, adds Natural Earth countries layer as the basemap for the map.
* `zoom_to_common_extent` when set to True, centers the map around all layers in the project.
* `extent` is alternative to `zoom_to_common_extent` and lets user specify the extent
as [`QgsRectangle`](https://qgis.org/pyqgis/master/core/QgsRectangle.html)

Check the marker api [documentation](https://docs.pytest.org/en/latest/mark.html)
and [examples](https://docs.pytest.org/en/latest/example/markers.html#marking-whole-classes-or-modules) for the ways
markers can be used.

### Utility tools

* `clean_qgis_layer` decorator found in `pytest_qgis.utils` is a decorator which can be used with `QgsMapLayer` fixtures to ensure that they are cleaned properly if they are used but not added to the `QgsProject`. This is only needed with layers with other than memory provider.
```python
# conftest.py of start of a test file
import pytest
from pytest_qgis.utils import clean_qgis_layer
from qgis.core import QgsVectorLayer

@pytest.fixture()
@clean_qgis_layer
def some_layer() -> QgsVectorLayer:
return QgsVectorLayer("layer_file.geojson", "some layer")

```


### Hooks

* `pytest_configure` hook is used to initialize and
configure [`QgsApplication`](https://qgis.org/pyqgis/master/core/QgsApplication.html). With QGIS >= 3.18 it is also
used to patch `qgis.utils.iface` with `qgis_iface` automatically.

### Command line options

* `--qgis_disable_gui` can be used to disable graphical user interface in tests. This speeds up the tests that use Qt
widgets of the plugin.
* `--qgis_disable_init` can be used to prevent QGIS (QgsApllication) from initializing. Mainly used in internal testing.

### ini-options

* `qgis_qui_enabled` whether the QUI will be visible or not. Defaults to `True`. Command line
option `--qgis_disable_gui` will override this.
* `qgis_canvas_width` width of the QGIS canvas in pixels. Defaults to 600.
* `qgis_canvas_height` height of the QGIS canvas in pixels. Defaults to 600.

## Requirements

This pytest plugin requires QGIS >= 3.10 to work.
Expand Down
25 changes: 13 additions & 12 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
# via -r requirements-dev.in
astor==0.8.1
# via flake8-qgis
atomicwrites==1.4.0
# via
# -c requirements.txt
# pytest
attrs==21.2.0
# via
# -c requirements.txt
Expand All @@ -25,21 +21,20 @@ bleach==3.3.1
# via readme-renderer
certifi==2021.5.30
# via requests
cffi==1.15.0
# via cryptography
cfgv==3.3.0
# via pre-commit
charset-normalizer==2.0.4
# via requests
click==8.0.3
# via black
colorama==0.4.4
# via
# -c requirements.txt
# click
# pytest
# tqdm
# twine
# via twine
coverage==5.5
# via pytest-cov
cryptography==36.0.0
# via secretstorage
distlib==0.3.2
# via virtualenv
docutils==0.17.1
Expand Down Expand Up @@ -76,6 +71,10 @@ iniconfig==1.1.1
# pytest
isort==5.10.1
# via -r requirements-dev.in
jeepney==0.7.1
# via
# keyring
# secretstorage
keyring==23.0.1
# via twine
mccabe==0.6.1
Expand Down Expand Up @@ -111,6 +110,8 @@ py==1.10.0
# pytest
pycodestyle==2.8.0
# via flake8
pycparser==2.21
# via cffi
pyflakes==2.4.0
# via flake8
pygments==2.9.0
Expand All @@ -126,8 +127,6 @@ pytest==6.2.4
# pytest-qgis
pytest-cov==2.12.1
# via -r requirements-dev.in
pywin32-ctypes==0.2.0
# via keyring
pyyaml==5.4.1
# via pre-commit
readme-renderer==29.0
Expand All @@ -142,6 +141,8 @@ requests-toolbelt==0.9.1
# via twine
rfc3986==1.5.0
# via twine
secretstorage==3.3.1
# via keyring
six==1.16.0
# via
# bleach
Expand Down
4 changes: 0 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@
#
# pip-compile
#
atomicwrites==1.4.0
# via pytest
attrs==21.2.0
# via pytest
colorama==0.4.4
# via pytest
iniconfig==1.1.1
# via pytest
packaging==21.0
Expand Down
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ classifiers =
package_dir =
= src
packages = find:
include_package_data = true
python_requires = >=3.5
install_requires =
pytest>=6.2.3
Expand All @@ -50,6 +51,7 @@ where = src
[options.package_data]
* =
py.typed
data/ne_50m_admin_0_countries.geojson

[options.entry_points]
pytest11 =
Expand All @@ -61,6 +63,7 @@ doctest_encoding = utf-8
[flake8]
max_line_length = 88
per-file-ignores =
src/pytest_qgis/pytest_qgis.py:QGS105
src/pytest_qgis/qgis_interface.py:N802,N803
tests/*:ANN001,ANN201
extend-ignore =
Expand Down
1 change: 1 addition & 0 deletions src/pytest_qgis/data/ne_50m_admin_0_countries.geojson

Large diffs are not rendered by default.

Loading