Testing
Testing
Flask-RMQ uses two deliberately separate test layers. The unit suite is fast, does not contact RabbitMQ, and measures branch coverage. The integration suite uses a real management-enabled RabbitMQ broker and validates AMQP behaviour that mocks cannot prove.
Unit tests
Install the development dependencies and the optional metrics extra, then run all tests except those marked integration:
uv sync --group dev --extra metrics
uv run pytest -m "not integration" \
--cov=flask_rmq --cov-branch --cov-report=term-missing --cov-fail-under=99The unit tests cover the connection, producer, consumer, queue, and registry contracts. Flask-specific tests cover extension initialization, application-state isolation, alias resolution, Click commands, and Prometheus instrumentation. Pika is mocked only at the connection/channel boundary.
Integration tests
Start the broker shipped with the repository and wait for its health check:
docker compose -f .github/docker-compose.yml up -d --wait
uv run pytest -m integration -v
docker compose -f .github/docker-compose.yml downThe integration suite verifies:
- round trips through the default and direct exchanges;
mandatory=True, publisher confirms, and passive declarations;- dead-letter routing after a handler failure;
- graceful consumer shutdown and
prefetch_countenforcement; - producer and consumer recovery after broker-side connection termination;
- isolation between aliases in separate virtual hosts;
- real topology setup and the
flask rmq consumecommand.
Connection settings come from RMQ_HOST, RMQ_PORT, RMQ_MGMT_PORT, RMQ_USER, RMQ_PASSWORD, and RMQ_VHOST. The defaults target localhost:5672, management port 15672, guest/guest, and /.
Each test creates UUID-suffixed queues and exchanges and removes them during teardown. Use a dedicated vhost when pointing the suite at a shared broker.
GitHub Actions runs unit tests on every supported Python version and integration tests across the supported Python/RabbitMQ matrix.