qx-testing
Testing helpers for Qx services — testcontainers, mediator and repository doubles, outbox assertions, and pytest fixture factories.
What lives here
qx.testing.postgres_container/redis_container/nats_container— context managers that start Docker containers via testcontainers. Each yields the running container with aget_connection_url()or equivalent accessor. Docker Desktop on macOS is detected automatically via~/.docker/run/docker.sock.qx.testing.MediatorStub— in-memoryMediatorreplacement. Pre-register handler return values withstub.on(CommandType, result). Asserts that each stubbed command was sent exactly once.qx.testing.RepositoryStub— in-memoryRepository[TEntity]backed by a plaindict. Supportsadd,get,list,save, andsoft_delete. No database required.qx.testing.OutboxAssert— queries the realqx_outbox_eventstable and providesassert_event_published(event_name, where={...}). Used in integration tests to verify that the transactional outbox was populated correctly.qx.testing.container_factory— pytest fixture that builds and tears down a DIContainerwith all singletons initialized.qx.testing.mediator_factory— pytest fixture that creates aMediatorwired to a test container.qx.testing.http_client_factory— pytest fixture that wraps a FastAPI app in aTestClientwith a fresh Prometheus registry per test.
Usage
Integration test with a real Postgres container
import pytest
from qx.testing.containers import postgres_container
from qx.testing.assertions import OutboxAssert
@pytest.fixture(scope="session")
def db_url():
with postgres_container() as pg:
yield pg.get_connection_url()
def test_create_user_writes_outbox(client, outbox: OutboxAssert):
client.post("/v1/users", json={"email": "a@b.com", "name": "Ada"})
import asyncio
asyncio.run(
outbox.assert_event_published(
"identity.user.registered",
where={"email": "a@b.com"},
)
)
Unit test with doubles
from qx.testing import MediatorStub, RepositoryStub
from qx.core import Result
async def test_create_user_handler():
users = RepositoryStub(User)
uow = FakeUnitOfWork(users)
handler = CreateUserHandler(uow)
result = await handler.handle(CreateUserCommand(email="a@b.com", name="Ada"))
assert result.is_success
assert len(users.all()) == 1
Design rules
- Use
NullPoolfor all test engines that callasyncio.run()in fixtures — asyncpg connections are bound to the event loop that created them and cannot be reused acrossasyncio.run()boundaries. RepositoryStubraises the sameNotFoundError/ConflictErrorshapes as the real repository so handler tests exercise error paths without a database.MediatorStub.assert_all_sent()can be called inteardownto catch unexpected commands that were sent but not stubbed.
Metadata
Release files for qx-testing 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| qx_testing-1.1.0.tar.gz | 8.5 kB | Without provenance | Details for qx_testing-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qx_testing-1.1.0-py3-none-any.whl | Python 3 | none | any | Details for qx_testing-1.1.0-py3-none-any.whl |
Total release size: 18.3 kB
Release files / qx_testing-1.1.0.tar.gz
| Download URL | qx_testing-1.1.0.tar.gz |
|---|---|
| Size | 8.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
21bf19d4a7d454240b1be119e7397e8d9170aab43a6fe2c0645d10609cf1893c
|
|
BLAKE2b-256 checksum How to use checksums |
341201c2dddc74d1327b776e81d4abeb3f9f4938047cfd243a1b77b82706bcd0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Release files / qx_testing-1.1.0-py3-none-any.whl
| Download URL | qx_testing-1.1.0-py3-none-any.whl |
|---|---|
| Size | 9.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
12a1be560fbd2123421606c574f4396d7bbf643babb986ee0ee582739860d4c9
|
|
BLAKE2b-256 checksum How to use checksums |
6b343cb1cd8d37039c19e816f3b0d75be9cb995c705b85a108a720b7dfd7bc1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Security for qx-testing 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.