Tests¶
This document outlines the testing process of opentemplate-based projects.
Features¶
- Uses
pytest⧉ for testing. - Collects doctests from source modules.
- Runs
pythoncode blocks from markdown files indocsand from docstrings viapytest-markdown-docs⧉ (usepython notestto skip a block). - Network is disabled in tests via
pytest-socket⧉; mark tests with@pytest.mark.enable_socketto allow it. - Fails tests running longer than
300seconds viapytest-timeout⧉. - Provides the
mockerfixture viapytest-mock⧉. - Annotates failures inline in GitHub pull requests via
pytest-github-actions-annotate-failures⧉. - Reports the
10slowest 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
testsdirectory, namedtest_.py. - Tests should follow
pyteststyle. - 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_underflag in[tool.coverage.report]section inpyproject.toml - To change mutation testing, update the
[tool.mutmut]section inpyproject.toml. - To change default
pytestoptions (network, markdown tests, timeout viatimeoutkey), update the[tool.pytest.ini_options]section inpyproject.toml. - To change the test runner, update the
tests-coveragescript in thepyproject.tomlfile.
Code sources¶
pyproject.toml.github/workflows/*tests*.yml.github/workflows/*typing*.yml