Skip to content

Commit 62387a6

Browse files
committed
Add test to catch error with async concurrent steps
1 parent be36f52 commit 62387a6

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from hamcrest import assert_that, has_entry, has_length
2+
from allure_commons_test.report import has_only_n_test_cases
3+
from allure_commons_test.result import has_step
4+
from allure_commons_test.result import with_status
5+
6+
def test_steps_could_be_run_cuncurrently_with_asyncio(executed_docstring_source):
7+
"""
8+
>>> import allure
9+
>>> import pytest
10+
>>> import asyncio
11+
12+
>>> async def run_steps(name, to_set, to_wait):
13+
... with allure.step(f"{name}-step"):
14+
... to_set.set()
15+
... await to_wait.wait()
16+
17+
>>> async def run_tasks():
18+
... task1_fence = asyncio.Event()
19+
... task2_fence = asyncio.Event()
20+
... await asyncio.gather(
21+
... run_steps("task1", task2_fence, task1_fence),
22+
... run_steps("task2", task1_fence, task2_fence)
23+
... )
24+
25+
>>> def test_asyncio_concurrency():
26+
... asyncio.get_event_loop().run_until_complete(
27+
... run_tasks()
28+
... )
29+
"""
30+
31+
assert_that(
32+
executed_docstring_source.allure_report,
33+
has_only_n_test_cases(
34+
"test_asyncio_concurrency",
35+
1,
36+
with_status("passed"),
37+
has_entry("steps", has_length(2)),
38+
has_step(
39+
"task1-step",
40+
with_status("passed")
41+
),
42+
has_step(
43+
"task2-step",
44+
with_status("passed")
45+
)
46+
),
47+
"Should contain a single test with two non-nested steps"
48+
)
49+

0 commit comments

Comments
 (0)