Pytest
The pytest macro executes Python test suites and stores their JUnit results.
Dependencies
Normal test execution requires pytest.
When coverage_dir is provided, the test suite is executed through coverage run.
This mode additionally requires coverage.
Features
pytest execution
JUnit XML generation
optional parallel coverage data collection
cikit data updates
XUnit artifact registration
Invalid test directories or invalid JUnit reports raise CiToolsError.
When pytest returns a non-zero exit code with valid JUnit results,
CiRecoverableError is raised after the metrics and artifacts have been saved.
This allows CiSection to retain the failure status while subsequent reports
can still be generated.
Typical usage
from pathlib import Path
from cikit.macros import pytest
pytest.pytest(env, Path("tests/unittests"), test_alias="unittests")
To collect coverage data for later processing:
pytest.pytest(env, Path("tests/unittests"), test_alias="unittests",
coverage_dir=Path("build/coverage"))