← Back to all products

Python Testing Toolkit

$29

Pytest fixtures, factories, mocking patterns, property-based testing, and CI integration for comprehensive test suites.

📁 27 files
TOMLMarkdownYAMLPythonGitHub Actions

📄 Product Preview

Try the interactive reader and demo tools below, or get the full product with all content unlocked.

📖 Interactive Reader (Free Preview) ⚙ Try Demo Tools 📦 Download Free Sample

📁 File Structure 27 files

python-testing-toolkit/ ├── LICENSE ├── README.md ├── ci/ │ ├── github-actions-pytest.yml │ └── pre-commit-config.yaml ├── examples/ │ ├── example_conftest.py │ ├── test_api_example.py │ ├── test_database_example.py │ └── test_property_based_example.py ├── free-sample.zip ├── guide/ │ ├── ci-integration.md │ ├── fixtures-and-factories.md │ ├── mocking-patterns.md │ ├── property-based-testing.md │ └── pytest-mastery-guide.md ├── guides/ │ ├── ci-integration.md │ ├── fixtures-and-factories.md │ ├── mocking-patterns.md │ ├── property-based-testing.md │ └── pytest-mastery-guide.md ├── index.html ├── pyproject.toml └── src/ └── testing_toolkit/ ├── __init__.py ├── assertions.py ├── builders.py ├── factories.py ├── fixtures.py └── mocks.py

📖 Documentation Preview README excerpt

Python Testing Toolkit

A comprehensive, battle-tested collection of pytest patterns, reusable fixtures, test-data factories, mocking utilities, and CI pipeline configurations. Built for Python developers who want reliable, maintainable, and fast test suites.

What's Inside

CategoryFilesDescription
Guides5 deep-dive documentsPytest mastery, fixtures & factories, mocking patterns, property-based testing, CI integration
Toolkit Source5 Python modulesReusable fixtures, factory builders, mock helpers, custom assertions, fluent builders
Examples4 annotated test filesAPI testing, database testing, property-based testing, conftest patterns
CI Configs2 pipeline filesGitHub Actions workflow, pre-commit hooks
Project Configpyproject.tomlPytest + coverage settings tuned for real projects

Quick Start


# 1. Copy the toolkit into your project
cp -r src/testing_toolkit/ your_project/tests/toolkit/

# 2. Copy the example conftest for reference
cp examples/example_conftest.py your_project/tests/conftest.py

# 3. Copy CI configs
cp ci/github-actions-pytest.yml your_project/.github/workflows/test.yml
cp ci/pre-commit-config.yaml your_project/.pre-commit-config.yaml

# 4. Add pytest config to your pyproject.toml (or copy ours as a starting point)
cat pyproject.toml

# 5. Run the example tests to verify everything works
pytest examples/ -v

Table of Contents

Guides

1. [Pytest Mastery Guide](guides/pytest-mastery-guide.md) — Architecture, fixtures deep-dive, scopes, parametrization, markers, plugin system, conftest layering

2. [Fixtures & Factories](guides/fixtures-and-factories.md) — Fixture patterns, test-data builders, deterministic fake data, database/session fixtures

3. [Mocking Patterns](guides/mocking-patterns.md) — unittest.mock, monkeypatch, patching strategies, autospec, time freezing, HTTP response mocking

4. [Property-Based Testing](guides/property-based-testing.md) — Hypothesis strategies, stateful testing, shrinking, integrating with pytest

5. [CI Integration](guides/ci-integration.md) — GitHub Actions matrix builds, coverage gates, xdist parallelization, flaky test detection

Source Modules

  • [testing_toolkit/factories.py](src/testing_toolkit/factories.py) — Deterministic fake data generators and model factories (stdlib only)
  • [testing_toolkit/fixtures.py](src/testing_toolkit/fixtures.py) — Reusable pytest fixtures: temp dirs, frozen clock, fake env, in-memory store
  • [testing_toolkit/mocks.py](src/testing_toolkit/mocks.py) — Mock helpers, spy objects, fake HTTP client with response recording
  • [testing_toolkit/assertions.py](src/testing_toolkit/assertions.py) — Custom assertion helpers with rich failure messages
  • [testing_toolkit/builders.py](src/testing_toolkit/builders.py) — Fluent test-data builders with chainable API

Examples

  • [test_api_example.py](examples/test_api_example.py) — Full API test suite demonstrating fixtures, mocks, parametrization
  • [test_database_example.py](examples/test_database_example.py) — Database testing with transactions, rollback fixtures, factory data
  • [test_property_based_example.py](examples/test_property_based_example.py) — Property-based tests with Hypothesis
  • [example_conftest.py](examples/example_conftest.py) — Annotated conftest showing layered fixture architecture

CI & Config

... continues with setup instructions, usage examples, and more.

📄 Code Sample .py preview

src/testing_toolkit/assertions.py """ Testing Toolkit — Custom assertion helpers with rich failure messages. Standard assert statements produce unhelpful messages when they fail. These helpers give you detailed, contextual failure output that tells you exactly what went wrong without needing a debugger. """ from __future__ import annotations import json import re from datetime import datetime, timedelta, timezone from typing import Any, Callable, Sequence # --------------------------------------------------------------------------- # Collection Assertions # --------------------------------------------------------------------------- def assert_contains_all(collection: Sequence, expected_items: Sequence, msg: str = "") -> None: """Assert that a collection contains ALL expected items. Unlike `assert set(expected) <= set(actual)`, this preserves order information in the failure message and works with non-hashable items. """ missing = [item for item in expected_items if item not in collection] if missing: context = msg + "\n" if msg else "" raise AssertionError( f"{context}" f"Collection is missing {len(missing)} expected item(s).\n" f"Missing items: {missing}\n" f"Collection has {len(collection)} items: {list(collection)[:20]}" f"{'...' if len(collection) > 20 else ''}" ) def assert_contains_none(collection: Sequence, forbidden_items: Sequence, msg: str = "") -> None: """Assert that a collection contains NONE of the forbidden items.""" found = [item for item in forbidden_items if item in collection] if found: context = msg + "\n" if msg else "" raise AssertionError( f"{context}" f"Collection contains {len(found)} forbidden item(s).\n" f"Found (but shouldn't be there): {found}\n" f"Collection: {list(collection)[:20]}" ) # ... 296 more lines ...
Buy Now — $29 Back to Products