smithery/cfircoo

pytest-best-practices

Expert guidance for writing high-quality pytest tests. Use when writing tests, setting up fixtures, parametrizing, mocking, or reviewing test code.

Installation

$ npx skills add smithery/cfircoo --skill pytest-best-practices

Similar popular skills

Related neighbors and high-traction skills in the same topics — useful to compare before installing.

Also in this package

Other skills from smithery/cfircoo.

npx skills add smithery/cfircoo

Browse all from smithery/cfircoo

More details

Agent compatibility

Declared targets from SKILL.md / docs. Unmarked agents are not listed — the skill may still install via the CLI.

Claude Code Not declared
Cursor Not declared
Codex Not declared
GitHub Copilot Not declared
Windsurf Not declared
Gemini CLI Not declared
Cline Not declared
OpenCode Not declared

Package contents

Files included with this skill beyond the listing page.

  • skill md SKILL.md 2,570 B
  • docs SUMMARY.md 176 B

History

  1. First recorded snapshot · 0 installs

SKILL.md

<objective> Provide pytest best practices and patterns for writing maintainable, efficient tests. </objective>

<essential_principles>

Test Independence

  • Each test must run in isolation - no shared state between tests
  • Use fixtures for setup/teardown, never class-level mutable state
  • Tests should pass regardless of execution order

Naming Conventions

  • Files: test.py or test.py
  • Functions: test_<description>()
  • Classes: Test<ClassName>
  • Fixtures: descriptive lowercasewithunderscores

Directory Structure

tests/
├── conftest.py          # Shared fixtures
├── unit/
│   └── test_module.py
├── integration/
│   └── test_api.py
└── fixtures/            # Test data files

Core Testing Rules

  • Use plain assert statements (pytest provides detailed failure messages)
  • One logical assertion per test when practical
  • Test edge cases: empty inputs, boundaries, invalid data, errors
  • Keep tests focused and readable

</essential_principles>

<quick_reference>

Pattern Use Case
@pytest.fixture Setup/teardown, dependency injection
@pytest.mark.parametrize Run test with multiple inputs
@pytest.mark.skip Skip test temporarily
@pytest.mark.xfail Expected failure (known bug)
pytest.raises(Exception) Test exception raising
pytest.approx(value) Float comparison
mocker.patch() Mock dependencies
conftest.py Share fixtures across modules

Common Commands

pytest -v                    # Verbose
pytest -x                    # Stop on first failure
pytest --lf                  # Run last failed
pytest -k "pattern"          # Match test names
pytest -m "marker"           # Run marked tests
pytest --cov=src             # Coverage report

</quick_reference>

<routing>

Based on what you're doing, read the relevant reference:

Task Reference
Setting up fixtures, scopes, factories references/fixtures.md
Parametrizing tests, multiple inputs references/parametrization.md
Mocking, patching, faking dependencies references/mocking.md
Markers, exceptions, assertions, async references/patterns.md

</routing>

<dependencies>

pip install pytest pytest-asyncio pytest-mock pytest-cov pytest-xdist

</dependencies>