pytest-testing_skill

This skill helps you master pytest testing with fixtures, mocking, and CI/CD integration to improve code quality and test coverage.
  • Python

3

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 pluginagentmarketplace/custom-plugin-python --skill pytest-testing

  • SKILL.md8.6 KB

Overview

This skill teaches practical pytest testing for Python projects, focusing on TDD, fixtures, mocking, and CI/CD integration. It helps you write reliable unit, integration, and functional tests, measure coverage, and automate test runs in pipelines. You'll learn patterns that make tests maintainable and fast to run.

How this skill works

The skill walks through pytest fundamentals: discovery, assertions, markers, and parametrization, then covers fixtures for setup/teardown across scopes. It shows mocking with unittest.mock and patching external dependencies, plus coverage measurement with pytest-cov. Finally, it demonstrates CI integration (GitHub Actions/GitLab), pre-commit hooks, and real-world project exercises to apply TDD and test automation.

When to use it

  • When adopting test-driven development for new features
  • When adding reliable unit and integration tests to an existing codebase
  • When isolating external dependencies with mocks during testing
  • When enforcing coverage thresholds and reporting in CI/CD
  • When organizing shared test setup with fixtures and conftest.py

Best practices

  • Write tests before implementation to drive design and keep focus on requirements
  • Use fixtures for reusable setup and prefer narrow scopes unless costly resources demand wider scope
  • Mock network, file I/O, and external services to keep tests deterministic and fast
  • Parametrize tests to cover multiple input cases without duplication
  • Integrate pytest-cov in CI and set a realistic coverage threshold, not as the only quality gate

Example use cases

  • TDD-driven calculator: write failing tests, implement features, aim for >90% coverage
  • API test suite: mock HTTP calls, test CRUD flows, and add authentication scenarios
  • Database tests: use fixtures that create a test database and roll back transactions after each test
  • CI pipeline: run pytest with coverage in GitHub Actions, upload coverage XML to Codecov

FAQ

Prefer function scope for isolation; use module or session scope only for expensive resources like a real database connection and ensure proper cleanup.

When should I mock vs use integration tests?

Mock when you need fast, deterministic unit tests; add integration tests against real services sparingly to validate end-to-end behavior.

How to enforce coverage in CI without blocking development?

Set a baseline coverage threshold in CI and use incremental goals. Fail builds for significant regressions but avoid overly strict thresholds early on.

Built by
VeilStrat
AI signals for GTM teams
© 2026 VeilStrat. All rights reserved.All systems operational
pytest-testing skill by pluginagentmarketplace/custom-plugin-python | VeilStrat