Skip to content

Commit ed0b280

Browse files
youtuxpbarnajc
authored andcommitted
Merge pull request pytest-dev#536 from pytest-dev/anonymous-step-funcs
Anonymous step funcs
1 parent 2284721 commit ed0b280

26 files changed

+158
-158
lines changed

pytest_bdd/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def pytest_addhooks(pluginmanager: PytestPluginManager) -> None:
3131
@given("trace")
3232
@when("trace")
3333
@then("trace")
34-
def trace() -> None:
34+
def _() -> None:
3535
"""Enter pytest's pdb trace."""
3636
pytest.set_trace()
3737

pytest_bdd/steps.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
Example:
44
55
@given("I have an article", target_fixture="article")
6-
def given_article(author):
6+
def _(author):
77
return create_test_article(author=author)
88
99
1010
@when("I go to the article page")
11-
def go_to_the_article_page(browser, article):
11+
def _(browser, article):
1212
browser.visit(urljoin(browser.url, "/articles/{0}/".format(article.id)))
1313
1414
1515
@then("I should not see the error message")
16-
def no_error_message(browser):
16+
def _(browser):
1717
with pytest.raises(ElementDoesNotExist):
1818
browser.find_by_css(".message.error").first
1919
@@ -22,15 +22,15 @@ def no_error_message(browser):
2222
2323
@given("I have an article")
2424
@given("there is an article")
25-
def article(author):
25+
def _(author):
2626
return create_test_article(author=author)
2727
2828
2929
Reusing existing fixtures for a different step name:
3030
3131
3232
@given("I have a beautiful article")
33-
def given_beautiful_article(article):
33+
def _(article):
3434
pass
3535
3636
"""

pytest_bdd/templates/test.py.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_${ make_python_name(scenario.name)}():
1919
% endfor
2020
% for step in steps:
2121
@${step.type}(${ make_string_literal(step.name)})
22-
def ${ make_python_name(step.name)}():
22+
def _():
2323
${make_python_docstring(step.name)}
2424
raise NotImplementedError
2525
% if not loop.last:

tests/args/cfparse/test_args.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ def values():
3737
3838
3939
@given(parsers.cfparse("I have {euro:d} Euro"))
40-
def i_have(euro, values):
40+
def _(euro, values):
4141
assert euro == values.pop(0)
4242
4343
4444
@when(parsers.cfparse("I pay {euro:d} Euro"))
45-
def i_pay(euro, values, request):
45+
def _(euro, values, request):
4646
assert euro == values.pop(0)
4747
4848
4949
@then(parsers.cfparse("I should have {euro:d} Euro"))
50-
def i_should_have(euro, values):
50+
def _(euro, values):
5151
assert euro == values.pop(0)
5252
5353
"""
@@ -89,17 +89,17 @@ def arguments():
8989
9090
9191
@given(parsers.cfparse("I have an argument {arg:Number}", extra_types=dict(Number=int)))
92-
def argument(arguments, arg):
92+
def _(arguments, arg):
9393
arguments["arg"] = arg
9494
9595
9696
@when(parsers.cfparse("I get argument {arg:d}"))
97-
def get_argument(arguments, arg):
97+
def _(arguments, arg):
9898
arguments["arg"] = arg
9999
100100
101101
@then(parsers.cfparse("My argument should be {arg:d}"))
102-
def assert_that_my_argument_is_arg(arguments, arg):
102+
def _(arguments, arg):
103103
assert arguments["arg"] == arg
104104
105105
"""

tests/args/parse/test_args.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ def values():
3636
3737
3838
@given(parsers.parse("I have {euro:d} Euro"))
39-
def i_have(euro, values):
39+
def _(euro, values):
4040
assert euro == values.pop(0)
4141
4242
4343
@when(parsers.parse("I pay {euro:d} Euro"))
44-
def i_pay(euro, values, request):
44+
def _(euro, values, request):
4545
assert euro == values.pop(0)
4646
4747
4848
@then(parsers.parse("I should have {euro:d} Euro"))
49-
def i_should_have(euro, values):
49+
def _(euro, values):
5050
assert euro == values.pop(0)
5151
5252
"""
@@ -87,17 +87,17 @@ def test_arguments():
8787
8888
8989
@given(parsers.parse("I have an argument {arg:Number}", extra_types=dict(Number=int)))
90-
def argument(arguments, arg):
90+
def _(arguments, arg):
9191
arguments["arg"] = arg
9292
9393
9494
@when(parsers.parse("I get argument {arg:d}"))
95-
def get_argument(arguments, arg):
95+
def _(arguments, arg):
9696
arguments["arg"] = arg
9797
9898
9999
@then(parsers.parse("My argument should be {arg:d}"))
100-
def assert_that_my_argument_is_arg(arguments, arg):
100+
def _(arguments, arg):
101101
assert arguments["arg"] == arg
102102
103103
"""

tests/args/regex/test_args.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ def values():
3535
return [1, 2, 1, 0, 999999]
3636
3737
@given(parsers.re(r"I have (?P<euro>\d+) Euro"), converters=dict(euro=int))
38-
def i_have(euro, values):
38+
def _(euro, values):
3939
assert euro == values.pop(0)
4040
4141
4242
@when(parsers.re(r"I pay (?P<euro>\d+) Euro"), converters=dict(euro=int))
43-
def i_pay(euro, values, request):
43+
def _(euro, values, request):
4444
assert euro == values.pop(0)
4545
4646
4747
@then(parsers.re(r"I should have (?P<euro>\d+) Euro"), converters=dict(euro=int))
48-
def i_should_have(euro, values):
48+
def _(euro, values):
4949
assert euro == values.pop(0)
5050
5151
"""
@@ -139,17 +139,17 @@ def test_arguments():
139139
pass
140140
141141
@given(parsers.re(r"I have an argument (?P<arg>\d+)"))
142-
def argument(arguments, arg):
142+
def _(arguments, arg):
143143
arguments["arg"] = arg
144144
145145
146146
@when(parsers.re(r"I get argument (?P<arg>\d+)"))
147-
def get_argument(arguments, arg):
147+
def _(arguments, arg):
148148
arguments["arg"] = arg
149149
150150
151151
@then(parsers.re(r"My argument should be (?P<arg>\d+)"))
152-
def assert_that_my_argument_is_arg(arguments, arg):
152+
def _(arguments, arg):
153153
assert arguments["arg"] == arg
154154
155155
"""

tests/feature/test_alias.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,24 @@ def test_alias():
3434
3535
3636
@given("I have an empty list", target_fixture="results")
37-
def results():
37+
def _():
3838
return []
3939
4040
4141
@given("I have foo (which is 1) in my list")
4242
@given("I have bar (alias of foo) in my list")
43-
def foo(results):
43+
def _(results):
4444
results.append(1)
4545
4646
4747
@when("I do crash (which is 2)")
4848
@when("I do boom (alias of crash)")
49-
def crash(results):
49+
def _(results):
5050
results.append(2)
5151
5252
5353
@then("my list should be [1, 1, 2, 2]")
54-
def check_results(results):
54+
def _(results):
5555
assert results == [1, 1, 2, 2]
5656
"""
5757
)

tests/feature/test_background.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,40 +34,40 @@ def foo():
3434
3535
3636
@given(parsers.re(r"a background step with multiple lines:\n(?P<data>.+)", flags=re.DOTALL))
37-
def multi_line(foo, data):
37+
def _(foo, data):
3838
assert data == "one\ntwo"
3939
4040
4141
@given('foo has a value "bar"')
42-
def bar(foo):
42+
def _(foo):
4343
foo["bar"] = "bar"
4444
return foo["bar"]
4545
4646
4747
@given('foo has a value "dummy"')
48-
def dummy(foo):
48+
def _(foo):
4949
foo["dummy"] = "dummy"
5050
return foo["dummy"]
5151
5252
5353
@given('foo has no value "bar"')
54-
def no_bar(foo):
54+
def _(foo):
5555
assert foo["bar"]
5656
del foo["bar"]
5757
5858
5959
@then('foo should have value "bar"')
60-
def foo_has_bar(foo):
60+
def _(foo):
6161
assert foo["bar"] == "bar"
6262
6363
6464
@then('foo should have value "dummy"')
65-
def foo_has_dummy(foo):
65+
def _(foo):
6666
assert foo["dummy"] == "dummy"
6767
6868
6969
@then('foo should not have value "bar"')
70-
def foo_has_no_bar(foo):
70+
def _(foo):
7171
assert "bar" not in foo
7272
7373
"""

tests/feature/test_cucumber_json.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,19 @@ def test_step_trace(testdir):
8080
from pytest_bdd import given, when, scenario, parsers
8181
8282
@given('a passing step')
83-
def a_passing_step():
83+
def _():
8484
return 'pass'
8585
8686
@given('some other passing step')
87-
def some_other_passing_step():
87+
def _():
8888
return 'pass'
8989
9090
@given('a failing step')
91-
def a_failing_step():
91+
def _():
9292
raise Exception('Error')
9393
9494
@given(parsers.parse('type {type} and value {value}'))
95-
def type_type_and_value_value():
95+
def _():
9696
return 'pass'
9797
9898
@scenario('test.feature', 'Passing')

tests/feature/test_description.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def test_description():
3636
3737
3838
@given("I have a bar")
39-
def bar():
39+
def _():
4040
return "bar"
4141
4242
def test_scenario_description():

0 commit comments

Comments
 (0)