-
Notifications
You must be signed in to change notification settings - Fork 226
/
Copy pathtest_async_scenarios.py
104 lines (91 loc) · 3.13 KB
/
test_async_scenarios.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""Test scenarios shortcut."""
import textwrap
from tests.utils import assert_outcomes
def test_scenarios(testdir, pytest_params):
"""Test scenarios shortcut (used together with @scenario for individual test override)."""
testdir.makeini(
"""
[pytest]
console_output_style=classic
"""
)
testdir.makeconftest(
"""
import pytest
from pytest_bdd import given
import anyio
@given('I have a bar')
async def i_have_bar():
await anyio.sleep(0)
print('bar!')
return 'bar'
"""
)
features = testdir.mkdir("features")
features.join("test.feature").write_text(
textwrap.dedent(
"""
@anyio
Scenario: Test scenario
Given I have a bar
"""
),
"utf-8",
ensure=True,
)
features.join("subfolder", "test.feature").write_text(
textwrap.dedent(
"""
@anyio
Scenario: Test subfolder scenario
Given I have a bar
@anyio
Scenario: Test failing subfolder scenario
Given I have a failing bar
@anyio
Scenario: Test already bound scenario
Given I have a bar
@anyio
Scenario: Test scenario
Given I have a bar
"""
),
"utf-8",
ensure=True,
)
testdir.makepyfile(
"""
import pytest
from pytest_bdd import scenarios, scenario
@pytest.mark.anyio
@scenario('features/subfolder/test.feature', 'Test already bound scenario', sync=False)
async def test_already_bound():
pass
scenarios('features', sync=False)
"""
)
result = testdir.runpytest_subprocess("-v", "-s", *pytest_params)
assert_outcomes(result, passed=8, failed=2)
result.stdout.fnmatch_lines(["*collected 10 items"])
result.stdout.fnmatch_lines(["*test_test_subfolder_scenario[[]asyncio[]] *bar!", "PASSED"])
result.stdout.fnmatch_lines(["*test_test_subfolder_scenario[[]trio[]] *bar!", "PASSED"])
result.stdout.fnmatch_lines(["*test_test_scenario[[]asyncio[]] *bar!", "PASSED"])
result.stdout.fnmatch_lines(["*test_test_scenario[[]trio[]] *bar!", "PASSED"])
result.stdout.fnmatch_lines(["*test_test_failing_subfolder_scenario[[]asyncio[]] *FAILED"])
result.stdout.fnmatch_lines(["*test_test_failing_subfolder_scenario[[]trio[]] *FAILED"])
result.stdout.fnmatch_lines(["*test_already_bound[[]asyncio[]] *bar!", "PASSED"])
result.stdout.fnmatch_lines(["*test_already_bound[[]trio[]] *bar!", "PASSED"])
result.stdout.fnmatch_lines(["*test_test_scenario_1[[]asyncio[]] *bar!", "PASSED"])
result.stdout.fnmatch_lines(["*test_test_scenario_1[[]trio[]] *bar!", "PASSED"])
def test_scenarios_none_found(testdir, pytest_params):
"""Test scenarios shortcut when no scenarios found."""
testpath = testdir.makepyfile(
"""
import pytest
from pytest_bdd import scenarios
scenarios('.', sync=False)
"""
)
result = testdir.runpytest_subprocess(testpath, *pytest_params)
assert_outcomes(result, errors=1)
result.stdout.fnmatch_lines(["*NoScenariosFound*"])