RabbitMQ process and client fixtures for pytest
Project description
pytest-rabbitmq
What is this?
A pytest plugin for tests that require a running RabbitMQ broker. It provides process and client fixtures.
How to use
The plugin contains two fixtures:
rabbitmq - it is a client fixture with function scope. After each test, it removes queues and exchanges created during the test to keep tests isolated and reliable.
rabbitmq_proc - a session-scoped fixture that starts a RabbitMQ instance at its first use and stops it at the end of the test session.
Simply include one of these fixtures in your test fixture list.
You can also create additional RabbitMQ client and process fixtures if you need to:
from pytest_rabbitmq import factories
rabbitmq_my_proc = factories.rabbitmq_proc(
port=None)
rabbitmq_my = factories.rabbitmq('rabbitmq_my_proc')
Prerequisites
Install RabbitMQ on the machine where tests are executed. The plugin starts a local RabbitMQ process and uses rabbitmq-server and rabbitmqctl binaries.
By default, binary paths are set to typical Linux locations:
/usr/lib/rabbitmq/bin/rabbitmq-server
/usr/lib/rabbitmq/bin/rabbitmqctl
If your environment uses different paths, override them with fixture arguments, command-line options, or pytest.ini settings described below.
Quickstart: first test
Install the plugin:
pip install pytest-rabbitmq
Create a test that uses the built-in fixture:
def test_rabbitmq_fixture_available(rabbitmq):
assert rabbitmq is not None
Run your tests:
pytest -q
Configuration
You can define settings in three ways: fixture factory argument, command-line option, and pytest.ini configuration option. You can pick which you prefer, but remember that these settings are handled in the following order:
Fixture factory argument
Command-line option
Configuration option in your pytest.ini file
RabbitMQ option |
Fixture factory argument |
Command-line option |
pytest.ini option |
Default |
|---|---|---|---|---|
host |
host |
–rabbitmq-host |
rabbitmq_host |
127.0.0.1 |
RABBITMQ_NODE_PORT |
port |
–rabbitmq-port |
rabbitmq_port |
random |
Port search count |
–rabbitmq-port-search-count |
rabbitmq_port_search_count |
5 |
|
RABBITMQ_DIST_PORT |
distribution_port |
–rabbitmq-distribution-port |
rabbitmq_distribution_port |
random |
rabbitmqctl path |
ctl |
–rabbitmq-ctl |
rabbitmq_ctl |
/usr/lib/rabbitmq/bin/rabbitmqctl |
rabbitmq server path |
server |
–rabbitmq-server |
rabbitmq_server |
/usr/lib/rabbitmq/bin/rabbitmq-server |
Plugin directory location |
plugin_path |
–rabbitmq-plugindir |
rabbitmq_plugindir |
$TMPDIR |
Node name |
node |
–rabbitmq-node |
rabbitmq_node |
rabbitmq-test-{port} |
Example usage:
Pass it as an argument in your own fixture.
rabbitmq_proc = factories.rabbitmq_proc(port=8888)Use the --rabbitmq-port command-line option when you run your tests.
pytest tests --rabbitmq-port=8888Specify your port as rabbitmq_port in your pytest.ini file.
To do so, put a line like the following under the [pytest] section of your pytest.ini:
[pytest] rabbitmq_port = 8888
Package resources
Bug tracker: https://github.com/dbfixtures/pytest-rabbitmq/issues
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytest_rabbitmq-4.0.0.tar.gz.
File metadata
- Download URL: pytest_rabbitmq-4.0.0.tar.gz
- Upload date:
- Size: 32.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dca99cba59324219a32638d840041ee20f961f85d3c8dcf7ac5b71bf29960aa1
|
|
| MD5 |
8f881b4e8b49c451fdfd2d03996e0e47
|
|
| BLAKE2b-256 |
3b0efe8bbe3a673fa3f94af48179c204b2c4574e684a289ad7e58ff3a5291894
|
File details
Details for the file pytest_rabbitmq-4.0.0-py3-none-any.whl.
File metadata
- Download URL: pytest_rabbitmq-4.0.0-py3-none-any.whl
- Upload date:
- Size: 30.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aba1feff10cb0faaad0ed16a001cd71fe1031bb8b1523166387d34d042065a26
|
|
| MD5 |
c2137383bf904f409329a9d5a45f3e74
|
|
| BLAKE2b-256 |
e207b6c0cacaa84c221595564dd2d0f2049b31242f2679d7bd277c369b14fa05
|