How to manage two "then" whose order is unknown ? #636
-
I work on a legacy product that trigger events but the order is not stable, i can get an event A then an event B or event B then event A. How can i write parallel 'then' because if event B is triggered before event A the log will be lost when the 'then' of event B will be started.
thanks for your help. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
pytest-bdd doesn't support that, you will have to come up with something that collects logs and that then checks the collected logs. Here is a suggestion of how the feature could look like: Feature: Foo
dectection of 2 events not ordered
Scenario: event A and event B detected
Given the system is ready
And I am collecting logs
When i do action
Then event A detected
And event B detected and the "I collect logs" could be defined as @pytest.fixture
def collected_logs():
return []
@then("I collect logs")
def _(shh_interraction, collected_logs, request):
shh_interraction.tail(callback=lambda log: collected_logs.append(log))
# make sure to stop the ssh connection at the end of the test
request.add_finalizer(lambda: ssh_interraction.disconnect())
@then("event A detected")
def check_event_A(shh_interraction):
assert any(log_expected(log, 'event A') for log in logs)
@then("event B detected")
def check_event_B(captured_logs):
assert any(log_expected(log, 'event B') for log in logs) |
Beta Was this translation helpful? Give feedback.
-
I forgot to update this discussion with my solution.
|
Beta Was this translation helpful? Give feedback.
pytest-bdd doesn't support that, you will have to come up with something that collects logs and that then checks the collected logs. Here is a suggestion of how the feature could look like:
and the "I collect logs" could be defined as