Create Tests
Generates idiomatic pytest test files for Python source code.
When to Use
- Writing tests for a new function or class.
- Adding missing coverage to an existing module.
- Scaffolding a test file from scratch.
Procedure
- Read the target source file to understand the public API and types.
- Check
tests/for existingconftest.py, fixtures, and naming patterns. - Consult pytest patterns reference for idiomatic examples.
- Determine test file path: mirror source under
tests/src/pkg/module.py→tests/pkg/test_module.py
- Write tests covering:
- Happy path (expected inputs/outputs)
- Edge cases (empty, boundary, large values)
- Error scenarios (
pytest.raiseswithmatch=) - Multiple inputs (
pytest.mark.parametrize)
- Mock all external dependencies (HTTP, DB, file I/O) with
unittest.mock(stdlib) orpytest-mockif already available. - Report what was created and any coverage gaps.
Requirements
- Type-annotate all test functions:
-> None. - Each test has a one-line docstring.
- Test names follow
test_<function>_<scenario>. - No repeated setup code — use fixtures or
parametrize.
Source: alisonpezzott/pyfabricops — distributed by TomeVault.