Skip to content

Commit e24aee0

Browse files
authored
Merge pull request #534 from pytest-dev/reusable-step-functions
Reusable step functions
2 parents 31dab36 + fa9192d commit e24aee0

File tree

11 files changed

+386
-195
lines changed

11 files changed

+386
-195
lines changed

CHANGES.rst

+5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Changelog
22
=========
33

4+
Unreleased
5+
----------
6+
- Fix bug where steps without parsers would take precedence over steps with parsers. `#534 <https://github.com/pytest-dev/pytest-bdd/pull/534>`_
7+
- Step functions can now be decorated multiple times with @given, @when, @then. Previously every decorator would override ``converters`` and ``target_fixture`` every at every application. `#534 <https://github.com/pytest-dev/pytest-bdd/pull/534>`_ `#525 <https://github.com/pytest-dev/pytest-bdd/issues/525>`_
8+
49
6.0.1
510
-----
611
- Fix regression introduced in 6.0.0 where a step function decorated multiple using a parsers times would not be executed correctly. `#530 <https://github.com/pytest-dev/pytest-bdd/pull/530>`_ `#528 <https://github.com/pytest-dev/pytest-bdd/issues/528>`_

README.rst

+5-6
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,11 @@ for `cfparse` parser
208208
from pytest_bdd import parsers
209209
210210
@given(
211-
parsers.cfparse("there are {start:Number} cucumbers",
212-
extra_types=dict(Number=int)),
211+
parsers.cfparse("there are {start:Number} cucumbers", extra_types={"Number": int}),
213212
target_fixture="cucumbers",
214213
)
215214
def given_cucumbers(start):
216-
return dict(start=start, eat=0)
215+
return {"start": start, "eat": 0}
217216
218217
for `re` parser
219218

@@ -223,11 +222,11 @@ for `re` parser
223222
224223
@given(
225224
parsers.re(r"there are (?P<start>\d+) cucumbers"),
226-
converters=dict(start=int),
225+
converters={"start": int},
227226
target_fixture="cucumbers",
228227
)
229228
def given_cucumbers(start):
230-
return dict(start=start, eat=0)
229+
return {"start": start, "eat": 0}
231230
232231
233232
Example:
@@ -301,7 +300,7 @@ You can implement your own step parser. It's interface is quite simple. The code
301300
302301
@given(parsers.parse("there are %start% cucumbers"), target_fixture="cucumbers")
303302
def given_cucumbers(start):
304-
return dict(start=start, eat=0)
303+
return {"start": start, "eat": 0}
305304
306305
307306
Override fixtures via given steps

poetry.lock

+94-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,13 @@ Mako = "*"
4040
parse = "*"
4141
parse-type = "*"
4242
pytest = ">=5.0"
43+
typing-extensions = "*"
4344

4445
[tool.poetry.dev-dependencies]
4546
tox = "^3.25.1"
4647
mypy = "^0.961"
4748
types-setuptools = "^57.4.18"
49+
pytest-xdist = "^2.5.0"
4850

4951
[build-system]
5052
requires = ["poetry-core>=1.0.0"]

pytest_bdd/generation.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from mako.lookup import TemplateLookup
1010

1111
from .feature import get_features
12-
from .scenario import find_argumented_step_fixture_name, make_python_docstring, make_python_name, make_string_literal
12+
from .scenario import find_argumented_step_function, make_python_docstring, make_python_name, make_string_literal
1313
from .steps import get_step_fixture_name
1414
from .types import STEP_TYPES
1515

@@ -132,9 +132,9 @@ def _find_step_fixturedef(
132132
if fixturedefs is not None:
133133
return fixturedefs
134134

135-
argumented_step_name = find_argumented_step_fixture_name(name, type_, fixturemanager)
136-
if argumented_step_name is not None:
137-
return fixturemanager.getfixturedefs(argumented_step_name, item.nodeid)
135+
step_func_context = find_argumented_step_function(name, type_, fixturemanager)
136+
if step_func_context is not None:
137+
return fixturemanager.getfixturedefs(step_func_context.name, item.nodeid)
138138
return None
139139

140140

0 commit comments

Comments
 (0)