python-testing_skill

This skill helps you write and run Python tests with pytest, coverage, fixtures, and mocks to improve reliability.
  • Shell

7

GitHub Stars

2

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 laurigates/claude-plugins --skill python-testing

  • REFERENCE.md2.2 KB
  • SKILL.md5.7 KB

Overview

This skill is a compact guide to writing and running Python tests using pytest, coverage, fixtures, parametrization, and mocking. It focuses on practical test organization, conftest.py usage, markers, async testing, and a TDD workflow. Use it to build reliable unit and integration test suites and to measure test coverage.

How this skill works

The skill describes common pytest commands, coverage options, and test patterns so you can run targeted test runs and generate reports. It explains fixtures (including scopes and autouse), parametrization, markers, async tests, and mocking techniques with unittest.mock and pytest-mock. It also shows recommended project layout, conftest.py patterns, and pyproject.toml settings to integrate pytest and coverage.

When to use it

  • Writing or organizing unit and integration tests with pytest
  • Implementing TDD cycles (red/green/refactor)
  • Creating reusable fixtures and shared test setup in conftest.py
  • Adding coverage measurement and HTML/terminal reports
  • Mocking external dependencies or testing async code

Best practices

  • Keep tests fast and focused; mark long-running tests (e.g., @pytest.mark.slow) and run them separately
  • Use conftest.py for shared fixtures; prefer explicit fixture names and appropriate scope
  • Parametrize repetitive assertions to avoid duplicated test code
  • Mock external services and heavy I/O; prefer dependency injection to simplify mocking
  • Add coverage reporting to CI and omit test files from coverage source configuration

Example use cases

  • Run all tests quickly: pytest -v or stop early with pytest -x
  • Measure coverage and show missing lines: pytest --cov --cov-report=term-missing
  • Share a database fixture in tests/conftest.py with scope='module' and teardown via yield
  • Parametrize input/output pairs to assert many cases in a single test function
  • Patch an external API with unittest.mock.patch or use pytest-mock's mocker fixture for cleaner syntax

FAQ

Use pytest.mark.asyncio on async test functions and create async fixtures with async def, awaiting client setup/teardown inside the fixture.

How do I run only slow or only fast tests?

Mark tests with @pytest.mark.slow and run them with pytest -m slow, or exclude slow tests with pytest -m "not slow".

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational