- Home
- Skills
- Autumnsgrove
- Groveengine
- Python Testing
python-testing_skill
- TypeScript
1
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill autumnsgrove/groveengine --skill python-testing- SKILL.md3.7 KB
Overview
This skill helps you write and run Python tests using pytest, with practical patterns for fixtures, mocking, parametrization, and coverage. It focuses on clear, maintainable tests using the Arrange-Act-Assert (AAA) pattern and standard pytest conventions. Use it to create test files, configure pytest, or troubleshoot test runs and coverage reports.
How this skill works
The skill provides concrete examples and templates for test structure, conftest fixtures, parametrized tests, mocking with unittest.mock, and environment-dependent testing using monkeypatch and tmp_path. It also supplies common pytest commands and a recommended pyproject.toml coverage configuration so you can run tests locally or in CI and produce meaningful coverage output. Follow the snippets to organize tests into unit, integration, and e2e directories and to name tests for discoverability.
When to use it
- Writing new unit, integration, or end-to-end tests for Python code
- Creating or updating conftest.py and shared fixtures
- Mocking external dependencies like HTTP calls or database clients
- Running tests locally, checking coverage, or preparing CI pipelines
- Refactoring tests to follow AAA for readability and reliability
Best practices
- Follow Arrange-Act-Assert for each test to keep intent clear.
- Centralize reusable fixtures in conftest.py and scope them appropriately (function, module, session).
- Use parametrization for input matrices instead of duplicating tests.
- Prefer monkeypatch or unittest.mock.patch to isolate external systems and make tests deterministic.
- Run pytest with coverage flags and add a minimal coverage threshold in CI.
- Name test files test_*.py and test functions test_* so pytest discovers them automatically.
Example use cases
- Unit test a service layer with fixtures that provide a fake database connection.
- Mock external API calls to verify error handling without network access.
- Write parametrized validators to verify many input cases in one test function.
- Use tmp_path to test file processing without touching the real filesystem.
- Add --cov=src to pytest runs and generate an HTML report for local inspection.
FAQ
Place shared fixtures in tests/conftest.py. Keep fixtures small and focused; use module or session scope when setup is costly.
When should I mock vs use a real dependency?
Mock external network, third-party services, or costly resources. Use real dependencies for integration tests that validate interactions end-to-end.