Skip to content

Commit

Permalink
Fix additional test suite issues (#637)
Browse files Browse the repository at this point in the history
* Fix conflicting tox environment factors

tox recognizes "cpython" as a valid Python version identifier
and rejects it in combination with "pyXY" identifiers:

```
ValueError: conflicting factors py310, cpython in py310-cpython-gevent
```

* Skip additional RabbitMQ tests if RabbitMQ is unreachable
  • Loading branch information
kurtmckee authored Jun 26, 2024
1 parent cfcf4fa commit 5a014da
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
19 changes: 19 additions & 0 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from contextlib import contextmanager

import pika
import pika.exceptions
import pytest

from dramatiq import Worker
from dramatiq.brokers.rabbitmq import RabbitmqBroker
from dramatiq.threading import is_gevent_active


Expand Down Expand Up @@ -33,3 +35,20 @@ def worker(*args, **kwargs):
RABBITMQ_USERNAME = os.getenv("RABBITMQ_USERNAME", "guest")
RABBITMQ_PASSWORD = os.getenv("RABBITMQ_PASSWORD", "guest")
RABBITMQ_CREDENTIALS = pika.credentials.PlainCredentials(RABBITMQ_USERNAME, RABBITMQ_PASSWORD)


def rabbit_mq_is_unreachable():
broker = RabbitmqBroker(
host="127.0.0.1",
max_priority=10,
credentials=RABBITMQ_CREDENTIALS,
)
try:
broker.connection
except pika.exceptions.AMQPConnectionError:
# RabbitMQ is unreachable
return True
return False


skip_unless_rabbit_mq = pytest.mark.skipif(rabbit_mq_is_unreachable(), reason="RabbitMQ is unreachable")
6 changes: 5 additions & 1 deletion tests/test_rabbitmq.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from dramatiq.brokers.rabbitmq import RabbitmqBroker, URLRabbitmqBroker, _IgnoreScaryLogs
from dramatiq.common import current_millis

from .common import RABBITMQ_CREDENTIALS, RABBITMQ_PASSWORD, RABBITMQ_USERNAME
from .common import RABBITMQ_CREDENTIALS, RABBITMQ_PASSWORD, RABBITMQ_USERNAME, skip_unless_rabbit_mq


def test_urlrabbitmq_creates_instances_of_rabbitmq_broker():
Expand All @@ -26,6 +26,7 @@ def test_urlrabbitmq_creates_instances_of_rabbitmq_broker():
assert isinstance(broker, RabbitmqBroker)


@skip_unless_rabbit_mq
def test_rabbitmq_broker_can_be_passed_a_semicolon_separated_list_of_uris():
# Given a string with a list of RabbitMQ connection URIs, including an invalid one
# When I pass those URIs to RabbitMQ broker as a ;-separated string
Expand All @@ -36,6 +37,7 @@ def test_rabbitmq_broker_can_be_passed_a_semicolon_separated_list_of_uris():
assert broker.connection


@skip_unless_rabbit_mq
def test_rabbitmq_broker_can_be_passed_a_list_of_uri_for_failover():
# Given a string with a list of RabbitMQ connection URIs, including an invalid one
# When I pass those URIs to RabbitMQ broker as a list
Expand Down Expand Up @@ -64,6 +66,7 @@ def test_rabbitmq_broker_raises_an_error_if_given_invalid_parameter_combinations
RabbitmqBroker(host="127.0.0.1", parameters=[dict(host="127.0.0.1")])


@skip_unless_rabbit_mq
def test_rabbitmq_broker_can_be_passed_a_list_of_parameters_for_failover():
# Given a list of pika connection parameters including an invalid one
parameters = [
Expand Down Expand Up @@ -217,6 +220,7 @@ def do_work():
assert xq_count == 1


@skip_unless_rabbit_mq
def test_rabbitmq_broker_connections_are_lazy():
# When I create an RMQ broker
broker = RabbitmqBroker(
Expand Down
5 changes: 2 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[tox]
envlist=
py{38,39,310,311,312}-cpython
py{38,39,310,311,312}-cpython-gevent
py{38,39,310,311,312}{,-gevent}
docs
lint

Expand All @@ -13,7 +12,7 @@ commands=
passenv=
TRAVIS

[testenv:py{38,39,310,311,312}-cpython-gevent]
[testenv:py{38,39,310,311,312}-gevent]
extras=
dev
commands=
Expand Down

0 comments on commit 5a014da

Please sign in to comment.