Code Testing
BERA Tools employs a pytest framework to ensure code quality and reliability. This document outlines the testing strategies, tools, and workflows used in the repository.
Testing Workflows
- pytest: Tests use pytest and are located in the
testsdirectory. The automated workflows described below run onlytests/test_workflow.py, not the complete test suite. - Automatic integration testing: The
python-integration-tests.ymlworkflow runstests/test_workflow.pyon pushes tomainand on qualifying pull requests targetingmainwhen its configured path filters match. - Coverage: Coverage from
tests/test_workflow.pyis printed in the GitHub Actions job log; it is not uploaded to an external service. - Runtime environment: The automatic integration workflow uses the Pixi-managed Python 3.12/GDAL environment.
- Manual compatibility testing: The dispatch-only
python-compatibility-tests.ymlworkflow runstests/test_workflow.pythrough tox in Python 3.12, 3.13, and 3.14 micromamba environments with conda-forge GDAL.
Running Tests Locally
To run tests locally, follow these steps:
- Install the required dependencies:
pip install .[dev]
- Run all the test suite using
pytest:
Discover and execute all tests in the tests directory.
pytest
Run a specific test file:
pytest tests/path/to/test_tools.py
Run a specific test function within a file:
pytest tests/path/to/test_tools.py::test_function_name
GitHub Actions
BERA Tools uses GitHub Actions to automate testing and deployment processes. This document describes the various workflows set up in the repository to ensure code quality and streamline releases.
-
python-compatibility-tests.yml: This dispatch-only workflow runs
tests/test_workflow.pythrough tox under Python 3.12, 3.13, and 3.14 in micromamba environments with conda-forge GDAL and native geospatial libraries. -
python-integration-tests.yml: This automatic workflow runs
tests/test_workflow.pywith terminal coverage on pushes tomainand qualifying pull requests targetingmain.
Refer to the Maintainer Guide for more information on these workflows.
Write Tests
It is required to write tests when contributing to BERA Tools. follow these guidelines to ensure consistency and quality in the test suite.
conftest.py
The conftest.py file in the tests directory contains shared fixtures and configurations for the test suite. You can add common setup code here that can be reused across multiple test files.
Test Organization
Tests are organized in the tests directory. Each module or tool should have a corresponding test file. .
Naming Conventions
Test files should be named with the prefix test_ which can be detected by pytest automatically. The test file name should be followed by the module or tool name (e.g., test_tools.py).
Writing Tests
When writing tests, use assertions to verify that the code behaves as expected. Utilize fixtures from conftest.py for setup and cleanup operations.