pytest-skill
pytest-skill equips you with patterns for writing robust Python tests using pytest's core features: fixtures for setup and teardown, parametrize for data-driven testing, markers for test organization, and mocking for external dependencies. It covers conftest configuration, exception handling, and best practices for production environments.
pytest-skill generates production-grade Python tests with fixtures, parametrize, markers, and mocking patterns.
AI-generated summary based on this skill's SKILL.md
Install
LambdaTest/agent-skills/pytest-skill · repository language: Python
git clone https://github.com/LambdaTest/agent-skills
cp -r agent-skills/pytest-skill ~/.claude/skills/pytest-skillnpx skillfed install LambdaTest/agent-skills/pytest-skillFrequently asked questions
AI-generated answers based on this skill's SKILL.md and metadata
How to write pytest tests with fixtures and parametrize?
pytest-skill teaches you to build production-grade tests using fixtures for setup/teardown and parametrize for data-driven testing. Fixtures provide reusable test components—database connections, mock objects, temporary files—while parametrize lets you run the same test logic across multiple input sets without code duplication. Together they enable clean, maintainable test suites.
What pytest patterns cover mocking, markers, and conftest setup?
pytest-skill covers mocking external dependencies using unittest.mock or pytest-mock, organizing tests with markers (@pytest.mark.skip, @pytest.mark.xfail, custom markers), and centralizing fixture definitions in conftest.py. These patterns let you isolate units under test, skip tests conditionally, and share fixtures across your entire test suite without repetition.
How do I write Python unit tests with proper assertion and exception handling?
pytest-skill demonstrates assertion techniques using pytest's assert statement with clear messages, and exception handling via pytest.raises() context manager. You learn to verify both success paths and error conditions—testing that functions raise expected exceptions with correct messages, ensuring your code fails gracefully and predictably.
How can pytest be configured for CI/CD with coverage and custom markers?
pytest-skill shows how to configure pytest in pyproject.toml or pytest.ini for CI/CD pipelines: enabling coverage collection, defining custom markers for test categorization, setting output formats, and integrating with tools like pytest-cov. This enables automated testing, coverage reporting, and selective test execution in continuous integration workflows.
What does pytest-skill teach about debugging and optimizing test execution?
pytest-skill covers debugging failing tests using -vv verbosity, --pdb for interactive debugging, and --lf to rerun last failures. For optimization, it addresses test organization, parallel execution with pytest-xdist, fixture scoping to minimize setup overhead, and identifying slow tests to improve CI/CD performance.
How does pytest-skill help with best practices for production testing?
pytest-skill emphasizes production-ready patterns: organizing tests in conftest for shared fixtures, using markers for test categorization, implementing proper exception handling, mocking external APIs and databases, and configuring coverage thresholds. These practices ensure your test suite is maintainable, reliable, and catches regressions before deployment.
SKILL.md
rendered from the published skill — quoted content, verbatim
Pytest Testing Skill
Core Patterns
Basic Test
import pytest
def test_addition():
assert 2 + 3 == 5
def test_exception():
with pytest.raises(ValueError, match="invalid"):
int("not_a_number")
class TestCalculator:
def test_add(self):
calc = Calculator()
assert calc.add(2, 3) == 5
def test_divide_by_zero(self):
with pytest.raises(ZeroDivisionError):
Calculator().divide(10, 0)
Fixtures
```python @pytest.fixture def calculator(): return Calculator()
@pytest.fixture def db_connection(): conn = Database.connect("test_db") yield conn # teardown after yield conn.rollback() conn.close()
@pytest.fixture(scope="module") def
(truncated - see the full file via the links below)
Read as markdown · JSON record · Browse the source repository
File tree — 3 files
pytest-skill/SKILL.md
pytest-skill/reference/advanced-patterns.md
pytest-skill/reference/playbook.md