Skip to content

Commit 9a9201a

Browse files
committed
Extract the check of the behaviour of step parsers in a new new test item
1 parent 757b055 commit 9a9201a

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

tests/generation/test_generate_missing.py

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ def test_generate_missing(testdir):
2525
2626
Background:
2727
Given I have a foobar
28-
And I have 3 baz
2928
3029
Scenario: Scenario tests which are already bound to the tests stay as is
3130
Given I have a bar
@@ -46,18 +45,14 @@ def test_generate_missing(testdir):
4645
"""\
4746
import functools
4847
49-
from pytest_bdd import scenario, given, parsers
48+
from pytest_bdd import scenario, given
5049
5150
scenario = functools.partial(scenario, "generation.feature")
5251
5352
@given("I have a bar")
5453
def i_have_a_bar():
5554
return "bar"
5655
57-
@given(parsers.parse("I have {n:d} baz"))
58-
def i_have_n_baz(n):
59-
return "baz"
60-
6156
@scenario("Scenario tests which are already bound to the tests stay as is")
6257
def test_foo():
6358
pass
@@ -85,10 +80,66 @@ def test_missing_steps():
8580
]
8681
)
8782

88-
assert 'Step Given "I have 3 baz" is not defined' not in result.stdout.str()
89-
9083
result.stdout.fnmatch_lines(
9184
['Step Given "I have a foobar" is not defined in the background of the feature "Missing code generation" *']
9285
)
9386

9487
result.stdout.fnmatch_lines(["Please place the code above to the test file(s):"])
88+
89+
90+
def test_generate_missing_with_step_parsers(testdir):
91+
"""Test that step parsers are correctly discovered and won't be part of the missing steps."""
92+
testdir.makefile(
93+
".feature",
94+
generation=textwrap.dedent(
95+
"""\
96+
Feature: Missing code generation with step parsers
97+
98+
Scenario: Step parsers are correctly discovered
99+
Given I use the string parser without parameter
100+
And I use parsers.parse with parameter 1
101+
And I use parsers.re with parameter 2
102+
And I use parsers.cfparse with parameter 3
103+
"""
104+
),
105+
)
106+
107+
testdir.makepyfile(
108+
textwrap.dedent(
109+
"""\
110+
import functools
111+
112+
from pytest_bdd import scenarios, given, parsers
113+
114+
scenarios("generation.feature")
115+
116+
@given("I use the string parser without parameter")
117+
def i_have_a_bar():
118+
return None
119+
120+
@given(parsers.parse("I use parsers.parse with parameter {param}"))
121+
def i_have_n_baz(param):
122+
return param
123+
124+
@given(parsers.re(r"^I use parsers.re with parameter (?P<param>.*?)$"))
125+
def i_have_n_baz(param):
126+
return param
127+
128+
@given(parsers.cfparse("I use parsers.cfparse with parameter {param:d}"))
129+
def i_have_n_baz(param):
130+
return param
131+
"""
132+
)
133+
)
134+
135+
result = testdir.runpytest("--generate-missing", "--feature", "generation.feature")
136+
assert_outcomes(result, passed=0, failed=0, errors=0)
137+
assert not result.stderr.str()
138+
assert result.ret == 0
139+
140+
output = result.stdout.str()
141+
142+
assert "I use the string parser" not in output
143+
assert "I use parsers.parse" not in output
144+
assert "I use parsers.re" not in output
145+
assert "I use parsers.cfparse" not in output

0 commit comments

Comments
 (0)