Getting Started
Introduction
The pytest-logikal package provides an improved pytest environment which automatically runs a broad range of checks:
Typing checks (via mypy and pytest-mypy)
Linting (via Pylint)
Code style checks (via isort, pycodestyle and pydocstyle)
Spelling checks (via codespell)
Coverage checks (via coverage.py and pytest-cov)
Security checks (via Bandit)
License checks (via pip-licenses)
Requirements lockfile checks (via pyorbs, when applicable)
Documentation checks (via logikal-docs, when applicable)
Package build checks (via build, when applicable)
The django
extra provides additional checks:
HTML template checks (via djLint)
CSS validation, style checks and linting (via v.Nu and Stylelint)
SVG validation (via v.Nu)
JavaScript style checks and linting (via ESLint)
Django migration linting (via Django migration linter)
Translation file checks (via Babel)
The black
extra provides even further checks:
Standardized code style and formatting checks (via Black)
The checks are configured to be strict, and all checks and tests are distributed across multiple CPUs by default (via pytest-xdist).
Installation
You can simply install pytest-logikal
from pypi:
pip install pytest-logikal
In addition to providing an opinionated default configuration, it also makes the output of the various pytest plugins more consistent.
Extras
black
The black
extra adds code style and formatting checks:
pip install pytest-logikal[black]
Note
We don’t use the Black standard style at Logikal because it forces function arguments to be overly terse occasionally, and because it prefers to enforce a double-quoted style for strings. We prefer using single quotes as they typically put less strain on the hand during typing, and as strings are typed and edited very often we believe this process should be as seamless as possible.
browser
The browser
extra installs Selenium and provides the
browser
fixture for convenient browser automation
in tests:
pip install pytest-logikal[browser]
When using the browser
extra you must specify the browser versions in your pyproject.toml
file as follows:
[tool.browser.versions]
chrome = '130.0.6723.69'
edge = '129.0.2792.65'
django
You may also use the django
extra to install the necessary packages, plugins and fixtures for
testing Django projects:
pip install pytest-logikal[django]
This will additionally install and configure django-stubs, pylint-django, pytest-django and pytest-factoryboy.
Note
Your system must have a working Node.js and npm installation that can be used to install and run Stylelint and ESLint.
Note
The v.Nu Docker Compose service must be available for the CSS and SVG validation
to work. We recommend adding the following service to your project’s compose.yml
file:
services:
validator:
image: ghcr.io/validator/validator:23.4.11
ports: [{target: 8888}]
When using the django
extra you must also specify the Django settings module and mypy plugin
path in your pyproject.toml
file as follows:
[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = 'project.settings.testing'
[tool.mypy]
plugins = ['mypy_django_plugin.main']
Configuration
You shall not change the standard, default configuration when working on Logikal software.
Nonetheless, regular configuration options for the various tools in the pyproject.toml
file
will be typically respected. Additionally, you can extend the allowed licenses and packages for
the license checker plugin as follows:
[tool.licenses]
extend_allowed_licenses = ['^Allowed License$']
[tool.licenses.extend_allowed_packages]
package = '^Package License$'
Note that the licenses are Python regular expressions that are matched from the beginning of the
actual license string. You can also override the default licenses and packages (instead of
extending them) via the tool.licenses.allowed_licenses
and tool.licenses.allowed_packages
options.