What problem does it solve?
Pytest conventions ensure tests are readable, maintainable, and reliable by enforcing consistent naming, structure, and use of fixtures and parametrization across a codebase.
Core Features & Use Cases
- Test file naming: Use descriptive file names like test_module.py.
- Test function naming: Follow the pattern test_<function><scenario><expected> to convey intent.
- Structure and fixtures: Apply Arrange-Act-Assert, and use fixtures to share setup without repetition.
- Parametrization and coverage: Use @pytest.mark.parametrize to run multiple inputs and promote thorough coverage.
- Test classes and organization: Group related tests in classes to reuse fixtures and setup.
Quick Start
Use these conventions to structure pytest tests across your project, starting with renaming your test files to match the test_ naming pattern and refactoring test functions to follow the naming scheme. Then add fixtures and parametrization per the guidelines. Finally, run your tests with pytest to verify and iterate.