š Smithery is now a part of Arcade.dev! Read more in our announcement here
Expert guidance for writing high-quality pytest tests. Use when writing tests, setting up fixtures, parametrizing, mocking, or reviewing test code.
Test Independence
Naming Conventions
test_*.py
*_test.py
test_<description>()
Test<ClassName>
lowercase_with_underscores
Directory Structure
tests/ āāā conftest.py # Shared fixtures āāā unit/ ā āāā test_module.py āāā integration/ ā āāā test_api.py āāā fixtures/ # Test data files
Core Testing Rules
assert
@pytest.fixture
@pytest.mark.parametrize
@pytest.mark.skip
@pytest.mark.xfail
pytest.raises(Exception)
pytest.approx(value)
mocker.patch()
conftest.py
Common Commands
pytest -v # Verbose pytest -x # Stop on first failure pytest --lf # Run last failed pytest -k "pattern" # Match test names pytest -m "marker" # Run marked tests pytest --cov=src # Coverage report
Based on what you're doing, read the relevant reference:
references/fixtures.md
references/parametrization.md
references/mocking.md
references/patterns.md