
Python Testing
- 176 installs
- 49 repo stars
- Updated August 4, 2026
- laurigates/claude-plugins
Author, extend, and debug pytest/unittest suites for Python modules, fixtures, mocks, and CI-friendly coverage targets.
About
python-testing from laurigates/claude-plugins helps you design reliable Python test suites with pytest conventions, isolated fixtures, meaningful assertions, and patterns that integrate cleanly into CI pipelines.
- pytest and unittest patterns
- Fixtures and mocking
- CI-ready test layout
- Regression coverage focus
- Python plugin ecosystem
Python Testing by the numbers
- 176 all-time installs (skills.sh)
- +5 installs in the week ending Aug 2, 2026 (Skillselion tracking)
- Ranked #838 of 2,153 Testing & QA skills by installs in the Skillselion catalog
- Data as of Aug 5, 2026 (Skillselion catalog sync)
npx skills add https://github.com/laurigates/claude-plugins --skill python-testingAdd your badge
Show developers this skill is listed on Skillselion. Paste this into your README.
| Installs | 176 |
|---|---|
| repo stars | ★ 49 |
| Last updated | August 4, 2026 |
| Repository | laurigates/claude-plugins ↗ |
What it does
Author, extend, and debug pytest/unittest suites for Python modules, fixtures, mocks, and CI-friendly coverage targets.
Files
Python Testing
Quick reference for Python testing with pytest, coverage, fixtures, and best practices.
When to Use This Skill
| Use this skill when... | Use pytest-advanced instead when... |
|---|---|
| Writing first pytest tests, learning fixtures and parametrization basics | Designing reusable conftest.py fixture hierarchies or parallel-execution markers |
Setting up coverage reporting and basic mocking with unittest.mock | Tuning pytest-xdist, custom markers, or hookimpl plugins |
| Following TDD red-green-refactor cycles on a single module | Building shared fixture libraries across a multi-package test suite |
When This Skill Applies
- Writing unit tests and integration tests
- Test-driven development (TDD)
- Test fixtures and parametrization
- Coverage analysis
- Mocking and patching
- Async testing
Quick Reference
Running Tests
# Basic test run
uv run pytest
# Verbose output
uv run pytest -v
# Show print statements
uv run pytest -s
# Stop at first failure
uv run pytest -x
# Run specific test
uv run pytest tests/test_module.py::test_function
# Run by keyword
uv run pytest -k "test_user"Test Coverage
# Run with coverage
uv run pytest --cov
# HTML report
uv run pytest --cov --cov-report=html
# Show missing lines
uv run pytest --cov --cov-report=term-missing
# Coverage for specific module
uv run pytest --cov=mymodule tests/Fixtures
import pytest
@pytest.fixture
def sample_data():
return {"key": "value"}
@pytest.fixture(scope="module")
def db_connection():
conn = create_connection()
yield conn
conn.close()
def test_with_fixture(sample_data):
assert sample_data["key"] == "value"Parametrize Tests
import pytest
@pytest.mark.parametrize("input,expected", [
("hello", "HELLO"),
("world", "WORLD"),
("test", "TEST"),
])
def test_uppercase(input: str, expected: str):
assert input.upper() == expected
@pytest.mark.parametrize("value,is_valid", [
(1, True),
(0, False),
(-1, False),
])
def test_validation(value, is_valid):
assert validate(value) == is_validMarkers
import pytest
@pytest.mark.slow
def test_slow_operation():
# Long-running test
pass
@pytest.mark.skip(reason="Not implemented yet")
def test_future_feature():
pass
@pytest.mark.skipif(sys.platform == "win32", reason="Unix only")
def test_unix_specific():
pass
@pytest.mark.xfail
def test_known_issue():
# Expected to fail
pass# Run only marked tests
uv run pytest -m slow
uv run pytest -m "not slow"Async Testing
import pytest
@pytest.mark.asyncio
async def test_async_function():
result = await async_operation()
assert result == expected_value
@pytest.fixture
async def async_client():
client = AsyncClient()
await client.connect()
yield client
await client.disconnect()Mocking
from unittest.mock import Mock, patch, MagicMock
def test_with_mock():
mock_obj = Mock()
mock_obj.method.return_value = "mocked"
assert mock_obj.method() == "mocked"
@patch('module.external_api')
def test_with_patch(mock_api):
mock_api.return_value = {"status": "success"}
result = call_external_api()
assert result["status"] == "success"
# pytest-mock (cleaner)
def test_with_mocker(mocker):
mock = mocker.patch('module.function')
mock.return_value = 42
assert function() == 42Test Organization
project/
├── src/
│ └── myproject/
│ ├── __init__.py
│ └── module.py
└── tests/
├── __init__.py
├── conftest.py # Shared fixtures
├── test_module.py
└── integration/
└── test_api.pyconftest.py
# tests/conftest.py
import pytest
@pytest.fixture(scope="session")
def app_config():
return {"debug": True, "testing": True}
@pytest.fixture(autouse=True)
def reset_db():
setup_database()
yield
teardown_database()pyproject.toml Configuration
[tool.pytest.ini_options]
testpaths = ["tests"]
python_files = ["test_*.py", "*_test.py"]
python_classes = ["Test*"]
python_functions = ["test_*"]
addopts = [
"-v",
"--strict-markers",
"--cov=src",
"--cov-report=term-missing",
]
markers = [
"slow: marks tests as slow",
"integration: marks tests as integration tests",
]
[tool.coverage.run]
source = ["src"]
omit = ["*/tests/*", "*/test_*.py"]
[tool.coverage.report]
exclude_lines = [
"pragma: no cover",
"def __repr__",
"raise AssertionError",
"raise NotImplementedError",
"if __name__ == .__main__.:",
]Common Testing Patterns
Test Exceptions
import pytest
def test_raises_exception():
with pytest.raises(ValueError):
function_that_raises()
def test_raises_with_message():
with pytest.raises(ValueError, match="Invalid input"):
function_that_raises()Test Warnings
import pytest
def test_deprecation_warning():
with pytest.warns(DeprecationWarning):
deprecated_function()Temporary Files
def test_with_tmp_path(tmp_path):
file_path = tmp_path / "test.txt"
file_path.write_text("content")
assert file_path.read_text() == "content"TDD Workflow
# 1. RED: Write failing test
uv run pytest tests/test_new_feature.py
# FAILED
# 2. GREEN: Implement minimal code
uv run pytest tests/test_new_feature.py
# PASSED
# 3. REFACTOR: Improve code
uv run pytest # All tests passSee Also
uv-project-management- Adding pytest to projectspython-code-quality- Combining tests with lintingpython-development- Core Python development patterns
References
- Official docs: https://docs.pytest.org/
- Detailed guide: See REFERENCE.md in this skill directory
Python Testing - Comprehensive Reference
Complete guide to Python testing with pytest.
Table of Contents
1. Test Discovery 2. Fixtures 3. Parametrization 4. Markers 5. Coverage 6. Mocking 7. Async Testing 8. Best Practices
---
Test Discovery
pytest automatically discovers tests following these conventions:
File names: test_*.py or *_test.py Function names: test_* Class names: Test* Methods: test_*
---
Fixtures
Fixtures provide reusable setup/teardown code:
import pytest
@pytest.fixture
def client():
return TestClient()
@pytest.fixture(scope="module")
def db():
db = setup_db()
yield db
teardown_db()
@pytest.fixture(autouse=True)
def reset_state():
# Runs before each test
clear_state()Scopes: function (default), class, module, package, session
---
Parametrization
Run the same test with different inputs:
@pytest.mark.parametrize("input,expected", [
(1, 2),
(2, 4),
(3, 6),
])
def test_double(input, expected):
assert double(input) == expected---
Markers
Custom test markers for organization:
@pytest.mark.slow
@pytest.mark.integration
def test_complex_operation():
passRun: pytest -m slow
---
Coverage
pytest --cov=src --cov-report=html
pytest --cov --cov-report=term-missing---
Mocking
from unittest.mock import patch
@patch('module.api_call')
def test_mocked(mock_api):
mock_api.return_value = {"data": "test"}
assert fetch_data() == {"data": "test"}---
Async Testing
@pytest.mark.asyncio
async def test_async():
result = await async_function()
assert result is not None---
Best Practices
1. One assertion per test 2. Use descriptive test names 3. Organize tests in classes 4. Use fixtures for setup 5. Mock external dependencies 6. Aim for 80%+ coverage
---
References
- pytest docs: https://docs.pytest.org/
- pytest-cov: https://pytest-cov.readthedocs.io/
- pytest-asyncio: https://pytest-asyncio.readthedocs.io/