Fixture
provide.testkit.quality.coverage.fixture
¶
Pytest fixtures for coverage tracking.
Classes¶
CoverageFixture
¶
Bases: BaseQualityFixture
Pytest fixture for coverage tracking integration.
Initialize coverage fixture.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any] | None
|
Coverage configuration |
None
|
artifact_dir
|
Path | None
|
Directory for artifacts |
None
|
Source code in provide/testkit/quality/coverage/fixture.py
Functions¶
auto_coverage
¶
Automatic coverage tracking fixture.
Automatically starts coverage at the beginning of the test and stops at the end. Ideal for tests that want zero-configuration coverage.
Usage
def test_automatic_coverage(auto_coverage): # Coverage automatically tracked result = some_function() assert result is not None # Coverage automatically stopped and saved
Source code in provide/testkit/quality/coverage/fixture.py
auto_coverage_marker
¶
Automatically apply coverage to marked tests.
Tests marked with @pytest.mark.coverage will automatically get coverage tracking without needing to explicitly use fixtures.
Source code in provide/testkit/quality/coverage/fixture.py
coverage_config
¶
Default coverage configuration fixture.
Returns standard coverage configuration that can be customized per test or project.
Usage
def test_with_custom_coverage(coverage_config): coverage_config["fail_under"] = 95 # Use with parametrized coverage_tracker
Source code in provide/testkit/quality/coverage/fixture.py
coverage_tracker
¶
coverage_tracker(
request: FixtureRequest, tmp_path: Path
) -> Generator[CoverageFixture, None, None]
Pytest fixture for coverage tracking.
Provides a CoverageFixture instance that automatically starts and stops coverage tracking around individual tests.
Usage
def test_with_coverage(coverage_tracker): coverage_tracker.start_tracking() # ... test code coverage_tracker.stop_tracking() assert coverage_tracker.get_coverage() > 80
Source code in provide/testkit/quality/coverage/fixture.py
parametrized_coverage
¶
parametrized_coverage(
request: FixtureRequest, tmp_path: Path
) -> Generator[CoverageFixture, None, None]
Parametrized coverage fixture for testing different configurations.
Automatically runs tests with different coverage configurations to validate behavior under various settings.
Usage
def test_coverage_configs(parametrized_coverage): # Test runs multiple times with different configs pass
Source code in provide/testkit/quality/coverage/fixture.py
pytest_configure
¶
Configure pytest with coverage markers.
Source code in provide/testkit/quality/coverage/fixture.py
session_coverage
¶
Session-wide coverage tracking.
Tracks coverage across all tests in the session. Useful for getting overall coverage metrics for the entire test suite.
Usage
def test_part_one(session_coverage): # Coverage tracked across all tests pass
def test_part_two(session_coverage): # Same coverage instance pass