pytest-advanced

Implement advanced Pytest markers, custom assertions, hooks, and coverage configuration.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill pytest-advanced
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: pytest-advanced
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-pytest/skills/pytest-advanced
Command: npx skills add https://github.com/TheBushidoCollective/han --skill pytest-advanced

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Master markers, custom assertions, hooks, and coverage configuration to enhance test suites.

Core Features & Use Cases

  • Markers & Custom Assertions: Custom markers for test organization and shared logic.
  • Hooks: Setup/teardown hooks for varied contexts.
  • Coverage: Configuring and collecting code coverage.

Quick Start

Create a suite using custom markers and a hook to run before tests.

Frequently Asked Questions about pytest-advanced

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I organize tests with custom markers in pytest?

Custom markers in pytest let you tag and group tests by category, then run specific subsets using -m flags. Define markers in pytest.ini or pyproject.toml, apply them as decorators to test functions, and execute pytest -m marker_name to filter runs. This enables logical test organization across unit, integration, and CI/CD workflows.

What are pytest hooks and when should I use them?

Pytest hooks are functions that run at specific lifecycle points—before tests start, after each test, or on failures. Implement them by defining functions like pytest_configure or pytest_runtest_setup in conftest.py to handle setup, teardown, reporting, or custom logic. Hooks enable consistent test context management without duplicating code.

How do I set up code coverage configuration in pytest?

Configure code coverage by installing pytest-cov, then add coverage settings to pytest.ini or pyproject.toml specifying source paths, omit patterns, and report formats. Run pytest --cov to collect metrics and generate reports. Proper configuration ensures accurate coverage tracking across your entire test suite.

Can I write custom assertion helpers in pytest?

Yes, create custom assertion functions in conftest.py or a utilities module that wrap pytest assertions with domain-specific logic. Use these helpers across tests to standardize error messages and validation patterns. Custom assertions improve test readability and reduce duplication when checking complex conditions.

Do pytest markers and hooks work together in the same test suite?

Markers and hooks work synergistically in pytest. Use markers to tag tests, then reference them inside hooks to apply conditional setup or teardown logic. For example, a hook can check for a marker and run environment-specific initialization, enabling flexible, layered test configuration.