pytest-patterns_skill

This skill helps you master Python testing with pytest, enabling reliable fixtures, parametrization, mocking, and scalable test organization.
  • Shell

40

GitHub Stars

3

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 manutej/luxor-claude-marketplace --skill pytest-patterns

  • EXAMPLES.md35.1 KB
  • README.md14.5 KB
  • SKILL.md46.5 KB

Overview

This skill teaches professional pytest patterns for building reliable Python test suites, covering fixtures, parametrization, mocking, and test organization. It focuses on practical patterns and workflows to scale tests, improve reliability, and integrate testing into CI pipelines.

How this skill works

The skill inspects common testing needs and provides concrete pytest patterns: fixture design and scopes, parametrization strategies, mocking and monkeypatch techniques, and directory/marker organization. It demonstrates how to compose fixtures, parametrize tests (including indirect and IDs), and use mocks/spies safely to isolate external dependencies.

When to use it

  • Starting a new Python project and establishing test infrastructure
  • Refactoring brittle or duplicated tests into reusable fixtures
  • Implementing TDD or expanding unit, integration, and e2e coverage
  • Testing code that depends on databases, APIs, or external services
  • Running tests reliably in CI with markers and selective execution

Best practices

  • Use fixtures for setup/teardown and prefer scoped fixtures (function/module/session) to control lifecycle
  • Parametrize tests to cover multiple cases without duplicating code and use IDs for readable output
  • Keep tests isolated: monkeypatch or mock external calls and avoid network/file system side effects when possible
  • Organize tests into unit/integration/e2e directories and share common fixtures via conftest.py
  • Use markers to categorize and selectively run slow or integration tests in CI
  • Make fixture factories for repeatable test data and ensure proper cleanup in yield blocks

Example use cases

  • Create a session-scoped database connection fixture for integration tests and a function-scoped clean_database fixture to reset state per test
  • Parametrize validation logic with pytest.mark.parametrize and pytest.param ids for clear failure lines
  • Mock external HTTP calls with monkeypatch or unittest.mock to simulate API responses and error paths
  • Build a make_user fixture factory to generate multiple user objects in a test and clean them up after
  • Tag long-running tests with @pytest.mark.slow and exclude them from default CI runs with -m "not slow"

FAQ

Use autouse fixtures sparingly for cross-cutting setup like resetting global state or configuring logging; prefer explicit fixtures when visibility and control are important.

How do I test code that requires multiple database backends?

Parametrize a database-type fixture (request.param) to run tests against each backend, and use indirect parametrization to pass values through the fixture constructor.

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