Skip to main content

fastapi-test-core

Core testing utilities for FastAPI services.

  • MockStack, MockConfig, MockSQLCursor — lightweight mocks activated as a stack;
  • create_mock, create_async_mock — one-liner MagicMock/AsyncMock factories from kwargs;
  • FixtureFactory, configuration_fixture — register domain fixtures from static methods, read config from a pytest marker;
  • as_async_generator, as_coroutine, asynchronous_calling, DeferredAsyncTask — async helpers;
  • assert_status_code, assert_api_error, assert_json_response — API response checks for httpx / requests / TestClient;
  • assert_async_called_with, assert_not_called, assert_called_once, assert_called_times, assert_dict_contains, assert_list_contains, assert_exception_message — mock-call asserts (mock_asserts.py, PyHamcrest);
  • slow, integration, unit, register_markers, skip_if_no_redis — pytest markers (markers.py);
  • JSONResponseDict, JSONResponseList, batch — response structures and reducers.
pip install fastapi-test-core

mock_asserts

Ассерты на вызовы моков поверх PyHamcrest:

from test_core import assert_called_once, assert_dict_contains

assert_called_once(mock_control.save)
assert_dict_contains(response.json(), {"status": "ok"})

markers

slow() / integration() / unit() — тонкие обёртки над pytest.mark. Регистрация:

# conftest.py
from test_core.markers import register_markers

def pytest_configure(config):
    register_markers(config)

skip_if_no_redis() — честная проверка: реальный TCP-коннект на REDIS_HOST/REDIS_PORT (default localhost:6379) с коротким таймаутом, skip только если недоступен. Не безусловный pytest.mark.skip, как было в осиротевшей test_utils.

MockConfig

extract(section, uppercase=True) ведёт себя как настоящий config_fastapi.Config.extract — рекурсивно приводит ключи извлечённой секции к верхнему регистру.

Changelog

1.2.0

  • create_mock/create_async_mock — перенесены из test_utils
  • новый модуль mock_asserts.py: assert_async_called_with, assert_not_called, assert_called_once, assert_called_times, assert_dict_contains, assert_list_contains, assert_exception_message
  • новый модуль markers.py: slow/integration/unit, register_markers(); skip_if_no_redis() переписан честно (реальный TCP-коннект с таймаутом), а не безусловный skip
  • MockConfig.extract(uppercase=True) — рекурсивный uppercase ключей, как в config_fastapi
  • зависимость pyhamcrest добавлена (требуется для mock_asserts.py)
  • пин pytest >=7.0,<10 — перенесено из неопубликованной 1.1.1
  • dev-группа зависимостей (pytest, pytest-asyncio, pytest-cov); собственный набор тестов библиотеки, покрытие 100%

1.1.0

  • MockStack, FixtureFactory, asserts, async-хелперы

Metadata

Release files for fastapi-test-core 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fastapi-test-core 1.2.0
File Size Uploaded
fastapi_test_core-1.2.0.tar.gz 7.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-test-core 1.2.0
File Interpreter ABI Platform
fastapi_test_core-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.8 kB

Release files / fastapi_test_core-1.2.0.tar.gz

Download URL fastapi_test_core-1.2.0.tar.gz
Size 7.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b236d7343500b675d16dd04444d6e2668372cd45f32e9866ae139c4ad45ac20f
BLAKE2b-256 checksum
How to use checksums
1bee92360374ab8593f77b7f657a3569a33629c528ec7e82ae4d7ba4e45c0933
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Release files / fastapi_test_core-1.2.0-py3-none-any.whl

Download URL fastapi_test_core-1.2.0-py3-none-any.whl
Size 10.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
28d538189b3ee084a209b70935d3e8b01c11ad55e3021026e2695ed39146f67a
BLAKE2b-256 checksum
How to use checksums
ec557d8b32999617eedca68ae2d68616c4cc91694a27743a042f207145cf923a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.0

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page