test_main.py Configuration
The MainTestConfigFile manages the tests/test_{package_name}/test_main.py
file.
Overview
Creates a test_main.py file that:
- Tests the CLI entry point (main.py)
- Uses the
main_test_fixturefixture - Ensures the CLI responds correctly
- Validates the main function exists and works
Inheritance
Inherits from: PythonPackageConfigFile
What this means:
- Python file with package structure
- Ensures parent directory is a valid Python package
- Text-based validation (checks for required content)
- Allows modifications as long as
test_mainfunction exists
File Location
Path: tests/test_{package_name}/test_main.py (e.g.,
tests/test_myapp/test_main.py)
Extension: .py - Python source file.
Filename: test_main - Test file for main.py.
Path transformation:
- Start with
pyrig.main→tests.test_pyrig.test_main - Replace
test_pyrigwithtest_{package_name}→tests.test_myapp.test_main - Convert to file path →
tests/test_myapp/test_main.py
How It Works
Automatic Generation
When initialized via uv run pyrig mkroot, the file is created with:
- Test function: A
test_mainfunction that uses themain_test_fixture - Fixture usage: The fixture validates the CLI works
- Simple assertion: Just checks the fixture returns None
Generated Content
"""test module."""
def test_main(main_test_fixture: None) -> None:
"""Test func for main."""
assert main_test_fixture is None
The test relies on the main_test_fixture fixture to do the actual
validation.
Validation Logic
The validation checks for the test function:
Required element: A def test_main function.
Flexible content: You can add additional tests or modify the implementation
as long as test_main exists.
Usage
Automatic Creation
uv run pyrig mkroot
Purpose
This file tests the CLI entry point by:
- Using the
main_test_fixturewhich runsuv run myapp --help - Ensuring the CLI responds without errors
- Validating the main function is properly configured
See the Testing documentation for details on the test infrastructure.
Best Practices
- Keep the test_main function: Don't remove it, as it validates the CLI
- Add more tests: You can add additional tests for CLI functionality
- Use the fixture: The
main_test_fixturedoes the heavy lifting - Test CLI commands: Add tests for your custom subcommands