Pytest testing patterns for Python covering fixtures, mocking, parametrization, and markers in one reference.
- CCM score
- 56 of 100
- skills.sh installs
- 301
- GitHub stars
- 681
- last updated
- Aug 21, 2026
Own this skill? Claim it
What it does
- Covers test structure, fixtures with teardown and scopes,
conftest.pysharing, mocking withunittest.mock, and async tests - Includes parametrize examples for input/expected pairs, custom markers for
slowandintegration, and a list of commonpytestcommand flags - Provides guidance on
pytest.raisesfor error assertions andskip/skipiffor conditional test execution - Designed for Python projects that need consistent test organization, with
pytest-asyncioandpytest-xdistnoted for async and parallel runs
Install
$ npx -y skills add gentleman-programming/gentleman-skills --skill pytest -yInstalls into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.
Files
Basic Test Structure
import pytest
class TestUserService:
def test_create_user_success(self):
user = create_user(name="John", email="john@test.com")
assert user.name == "John"
assert user.email == "john@test.com"
def test_create_user_invalid_email_fails(self):
with pytest.raises(ValueError, match="Invalid email"):
create_user(name="John", email="invalid")
Fixtures
import pytest
@pytest.fixture
def user():
"""Create a test user."""
return User(name="Test User", email="test@example.com")
@pytest.fixture
def authenticated_client(client, user):
"""Client with authenticated user."""
client.force_login(user)
return client
# Fixture with teardown
@pytest.fixture
def temp_file():
path = Path("/tmp/test_file.txt")
path.write_text("test content")
yield path # Test runs here
path.unlink() # Cleanup after test
# Fixture scopes
@pytest.fixture(scope="module") # Once per module
@pytest.fixture(scope="class") # Once per class
@pytest.fixture(scope="session") # Once per test session
conftest.py
# tests/conftest.py - Shared fixtures
import pytest
Details
- Repository
- github.com/gentleman-programming/gentleman-skills
- Categories
- Testing & QA, Python
- First seen
- Jun 3, 2026
Questions
What does the pytest skill help an AI agent do?
The pytest skill teaches an AI agent Pytest testing patterns for Python. It covers writing tests with fixtures, mocking, parametrize, markers, and async tests, plus common pytest commands for running them.
How do I install the pytest skill?
Run npx -y skills add gentleman-programming/gentleman-skills --skill pytest -y in your project. Once installed, the agent can follow these Pytest patterns when you write Python tests.
Where does the pytest skill stand in the Testing & QA category?
The pytest skill sits in the Testing & QA category on Claude Marketplaces. Other skills in that category include tdd, test-driven-development, webapp-testing and break-ui, which cover different testing approaches.
Does the pytest skill cover mocking and fixtures?
Yes, the skill covers fixtures with setup and teardown, fixture scopes, conftest.py shared fixtures, and mocking with unittest.mock patch and MagicMock. It also shows parametrized tests and custom markers.
More from gentleman-programming/gentleman-skills
All 13Similar to Pytest
More Testing & QApython-testing-patternsSkillwshobson/agents42.2K installsComprehensive pytest guide covering fixtures, mocking, parameterization, and test-driven development workflows for Python.
jutsu-pytestPluginTheBushidoCollective/han201 starsComprehensive Pytest testing framework skills for Python projects with fixtures, plugins, and advanced testing patterns.
vitest-testingSkillexistential-birds/beagle473 installsStructured guide of Vitest patterns covering unit and integration tests, assertions, async handling, and mocking.
unit-testing-frameworkSkillaj-geddes/useful-ai-prompts637 installsStructured guidance for writing unit tests with Jest, pytest, JUnit, or RSpec, following the AAA pattern.
testing-patternsSkillvudovn/ag-kit218 installsReference guide of testing principles covering the test pyramid, AAA structure, and mocking strategies for reliable suites.