Overview
Themktests command creates test files mirroring the source package structure. For each module, class, function, and method in the source code, it generates corresponding test skeletons with NotImplementedError placeholders.
What It Does
The command:- Scans your source package for all modules, classes, functions, and methods
- Generates test files mirroring the source structure in the
tests/directory - Creates test skeletons with proper naming conventions
- Adds placeholders with
NotImplementedErrorfor unimplemented tests - Preserves existing tests - only adds new skeletons for untested code
- Uses parallel execution for performance on large codebases
The command is idempotent and non-destructive: safe to run multiple times, only adds new test skeletons, preserves all existing tests.
Naming Conventions
The generated tests follow strict naming patterns:test_<module_name>.pyTest<ClassName>test_<function_name>test_<method_name>Usage
Basic Usage
After Adding New Code
With Verbose Output
Quiet Mode
Generated Test Structure
Given this source code:Expected Output
Behavior
Automatically discovers all modules in your source package by scanning the package directory.
Test structure exactly mirrors source structure:
- Never overwrites existing test functions
- Only adds new test skeletons for untested code
- Preserves all manual test implementations
Uses parallel execution (ThreadPoolExecutor) for fast generation on large codebases.
Generated test functions raise
NotImplementedError to ensure they must be implemented before passing.When to Use
Use mktests When:
- You’ve added new modules, classes, or functions
- Starting a new project and need initial test structure
- Ensuring test coverage completeness
- You want to enforce test-driven development
- Auditing which code lacks tests
Example Workflow
Implement the tests
Edit the generated test files and replace
NotImplementedError with actual test logic.Test Docstrings
Generated tests include minimal docstrings:Excluding Test Generation
To skip test generation for specific code, use naming conventions:- Private functions/methods: Start with
_(not tested by default) - Internal modules: Mark as internal in module docstring
Related Commands
Implementation
Themktests command calls MirrorTestConfigFile.I.create_all_test_modules(), which discovers all source modules and creates test skeletons. See pyrig/rig/cli/commands/create_tests.py:11.
Run
uv run pyrig mktests --help to see the command’s built-in help text.