API Reference¶
This section provides comprehensive API documentation for pytest-test-categories.
Overview¶
pytest-test-categories provides a complete API for categorizing tests by size, enforcing resource isolation, validating test distribution, and generating reports.
Contents¶
Markers Reference¶
Documentation for all pytest markers provided by the plugin:
Size Markers:
@pytest.mark.small,@pytest.mark.medium,@pytest.mark.large,@pytest.mark.xlargeBase Test Classes:
SmallTest,MediumTest,LargeTest,XLargeTestMarker Inheritance: Class-level, module-level, and precedence rules
Fixtures Reference¶
Guidance on fixture usage with pytest-test-categories:
Recommended Fixtures: Best practices for each test size
Fixture Scope: Scope recommendations by test category
Compatibility: Integration with pytest-mock, pytest-django, etc.
Error Messages Reference¶
Comprehensive index of all error codes and messages:
TC001-TC005: Resource isolation violations (network, filesystem, process, database, sleep)
TC006: Timing violations
TC007: Distribution warnings
Exception Hierarchy: All exception classes and their relationships
Quick Links¶
Topic |
Description |
|---|---|
All CLI and ini options |
|
Size markers and base classes |
|
Fixture recommendations |
|
Error codes and resolution |
Module Reference¶
Core Modules¶
Module |
Description |
|---|---|
|
Pytest hook implementations |
|
Core type definitions (TestSize, TestTimer, etc.) |
|
Time limit configuration and validation |
|
Base test classes for inheritance |
Exception Modules¶
Module |
Description |
|---|---|
|
Error code registry |
|
Exception classes for violations |
Service Modules¶
Module |
Description |
|---|---|
|
Test size marker discovery |
|
Timing validation logic |
|
Distribution validation |
|
Report generation |
Adapter Modules¶
Module |
Description |
|---|---|
|
Network blocking implementation |
|
Filesystem blocking implementation |
|
Subprocess blocking implementation |
|
Database blocking implementation |
|
Sleep blocking implementation |
Public API¶
Markers¶
import pytest
# Size markers
@pytest.mark.small # Unit tests, 1s limit
@pytest.mark.medium # Integration tests, 5min limit
@pytest.mark.large # E2E tests, 15min limit
@pytest.mark.xlarge # Extended tests, 15min limit
# With parameters
@pytest.mark.medium(allow_external_systems=True)
Base Classes¶
from pytest_test_categories import SmallTest, MediumTest, LargeTest, XLargeTest
class MyUnitTests(SmallTest):
def test_example(self):
pass
Types¶
from pytest_test_categories.types import TestSize
# Enum values
TestSize.SMALL
TestSize.MEDIUM
TestSize.LARGE
TestSize.XLARGE
# Properties
size.marker_name # 'small', 'medium', etc.
size.label # '[SMALL]', '[MEDIUM]', etc.
size.network_mode # NetworkMode enum value
Exceptions¶
from pytest_test_categories.exceptions import (
HermeticityViolationError,
NetworkAccessViolationError,
FilesystemAccessViolationError,
SubprocessViolationError,
DatabaseViolationError,
SleepViolationError,
)
from pytest_test_categories.timing import TimingViolationError
from pytest_test_categories.services.distribution_validation import DistributionViolationError
Version Compatibility¶
pytest-test-categories |
Python |
pytest |
|---|---|---|
1.x |
3.11+ |
7.0+ |
Source Code¶
The complete source code is available on GitHub:
Repository: github.com/mikelane/pytest-test-categories
Source:
src/pytest_test_categories/