Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
feudal
feudalBackend
Commits
d0b390e3
Commit
d0b390e3
authored
Apr 06, 2020
by
lukas.burgey
Browse files
Disable the broker if run with pytest
parent
cc8b155b
Pipeline
#81075
passed with stage
in 1 minute and 7 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
feudal/backend/brokers.py
View file @
d0b390e3
import
sys
import
os
from
logging
import
getLogger
from
pika
import
BlockingConnection
,
ConnectionParameters
,
BasicProperties
...
...
@@ -27,6 +29,18 @@ class RabbitMQInstance:
'services'
,
]
@
property
def
_no_broker
(
self
):
""" indicates if this module should do anything.
This is useful during testing, when there may not be a running RabbitMQ server
"""
return
(
'pytest'
in
sys
.
modules
or
getattr
(
settings
,
'NO_BROKER'
,
False
)
or
os
.
path
.
basename
(
sys
.
argv
[
0
])
in
(
'pytest'
,
'py.test'
)
)
def
_init_exchanges
(
self
,
channel
):
# this is no error
for
exchange
in
self
.
exchanges
:
...
...
@@ -66,7 +80,7 @@ class RabbitMQInstance:
def
_publish
(
self
,
exchange
,
routing_key
,
body
):
# when running CI tests we have no broker, so just do nothing
if
getattr
(
settings
,
'NO_BROKER'
,
False
)
:
if
self
.
_no_broker
:
return
connection
=
self
.
_open_connection
()
...
...
@@ -92,7 +106,7 @@ class RabbitMQInstance:
# called on client registration to make sure the exchanges exists
def
initialize
(
self
):
# when running CI tests we have no broker, so just do nothing
if
getattr
(
settings
,
'NO_BROKER'
,
False
)
:
if
self
.
_no_broker
:
return
connection
=
self
.
_open_connection
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment