pytest-testing_skill

This skill helps you write and run pytest tests efficiently, organize fixtures, and improve coverage with practical guidance.
  • Python

6

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 trotsky1997/my-claude-agent-skills --skill pytest-testing

  • SKILL.md8.5 KB

Overview

This skill is a practical, hands-on guide for writing and running pytest tests in Python projects. It covers setup, test organization, fixtures, parametrization, mocking, coverage, debugging, and CI integration to help you ship reliable code. Use it to adopt pytest conventions and improve test quality quickly.

How this skill works

The guide describes how to install pytest and pytest-cov, structure test files, and configure pytest via pytest.ini or pyproject.toml. It explains fixtures, scopes, assertions, parametrized tests, mocking with unittest.mock, coverage reporting, and common debugging commands. It also shows CI examples and common fixes for import/fixture/coverage problems.

When to use it

  • Setting up pytest for a new project
  • Writing unit, integration, or CLI tests
  • Creating and reusing fixtures and parametrized cases
  • Isolating code with mocks and testing exceptions
  • Measuring and improving test coverage
  • Debugging failing tests and integrating with CI/CD

Best practices

  • Keep tests independent; avoid global state and ordering dependencies
  • Favor fixtures over globals for setup and teardown; choose appropriate fixture scopes
  • Name files, classes, and functions using pytest conventions (test_*, Test*, test_*)
  • Write descriptive test names and add short docstrings for intent
  • Test both happy paths and edge cases, including error conditions
  • Use markers (slow, integration, unit) to filter tests and keep CI fast

Example use cases

  • Quickly scaffold tests: install pytest, add tests/ and pytest.ini, run pytest -v
  • Create reusable fixtures in conftest.py for shared setup like DB sessions or temp files
  • Parametrize input sets to validate multiple values with a single test function
  • Mock external dependencies (API calls, argv) to isolate logic and assert interactions
  • Run coverage locally and produce HTML or CI reports with pytest --cov and pytest-cov

FAQ

Use the node id: pytest tests/test_file.py::TestClass::test_method or pytest tests/test_file.py::test_function

Why isn’t my fixture found?

Ensure the fixture is defined in the same test file or in conftest.py under tests/, and verify pytest’s testpaths and python_files settings in configuration.

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