Skip to content

Tests

This document outlines the testing process of opentemplate-based projects.

Features

  • Uses pytest ⧉ for testing.
  • Collects doctests from source modules.
  • Runs python code blocks from markdown files in docs and from docstrings via pytest-markdown-docs ⧉ (use python notest to skip a block).
  • Network is disabled in tests via pytest-socket ⧉; mark tests with @pytest.mark.enable_socket to allow it.
  • Fails tests running longer than 300 seconds via pytest-timeout ⧉.
  • Provides the mocker fixture via pytest-mock ⧉.
  • Annotates failures inline in GitHub pull requests via pytest-github-actions-annotate-failures ⧉.
  • Reports the 10 slowest tests and a summary of all non-passed outcomes.
  • Measures test coverage with coverage ⧉ (default threshold: 100%).
  • Local testing: Runs on the latest three Python versions, following SPEC 0 ⧉.
  • CI testing: Runs across multiple Python versions and OSs (Linux, macOS, Windows) via GitHub Actions.
  • Randomized test execution ensures independence.
  • Includes Hypothesis ⧉ for property-based testing.

Note

tox is not used; instead, tests are run with different interpreters locally and across CI runners.

Writing tests

  • All tests are in the tests directory, named test_.py.
  • Tests should follow pytest style.
  • Recommended: Use Hypothesis ⧉ for property-based testing, as required by OSSF Scorecard ⧉.

Tip

opentemplate does not enforce a specific testing style, but methodologies like Test/Behavior Driven Development may be beneficial.

Checks and fixes

Tests should be documented, formatted, and typed as they will be checked like regular source code.

Tip

See the Python section for more information.

Adjustments

Note

All changes apply to the CI as well.

  • To change coverage requirements, update the fail_under flag in [tool.coverage.report] section in pyproject.toml
  • To change mutation testing, update the [tool.mutmut] section in pyproject.toml.
  • To change default pytest options (network, markdown tests, timeout via timeout key), update the [tool.pytest.ini_options] section in pyproject.toml.
  • To change the test runner, update the tests-coverage script in the pyproject.toml file.

Code sources

  • pyproject.toml
  • .github/workflows/*tests*.yml
  • .github/workflows/*typing*.yml