Skip to content

Commit

Permalink
Merge pull request #534 from pytest-dev/reusable-step-functions
Browse files Browse the repository at this point in the history
Reusable step functions
  • Loading branch information
youtux authored Jul 15, 2022
2 parents 31dab36 + fa9192d commit e24aee0
Show file tree
Hide file tree
Showing 11 changed files with 386 additions and 195 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changelog
=========

Unreleased
----------
- Fix bug where steps without parsers would take precedence over steps with parsers. `#534 <https://github.com/pytest-dev/pytest-bdd/pull/534>`_
- 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>`_

6.0.1
-----
- 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>`_
Expand Down
11 changes: 5 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,11 @@ for `cfparse` parser
from pytest_bdd import parsers
@given(
parsers.cfparse("there are {start:Number} cucumbers",
extra_types=dict(Number=int)),
parsers.cfparse("there are {start:Number} cucumbers", extra_types={"Number": int}),
target_fixture="cucumbers",
)
def given_cucumbers(start):
return dict(start=start, eat=0)
return {"start": start, "eat": 0}
for `re` parser

Expand All @@ -223,11 +222,11 @@ for `re` parser
@given(
parsers.re(r"there are (?P<start>\d+) cucumbers"),
converters=dict(start=int),
converters={"start": int},
target_fixture="cucumbers",
)
def given_cucumbers(start):
return dict(start=start, eat=0)
return {"start": start, "eat": 0}
Example:
Expand Down Expand Up @@ -301,7 +300,7 @@ You can implement your own step parser. It's interface is quite simple. The code
@given(parsers.parse("there are %start% cucumbers"), target_fixture="cucumbers")
def given_cucumbers(start):
return dict(start=start, eat=0)
return {"start": start, "eat": 0}
Override fixtures via given steps
Expand Down
108 changes: 94 additions & 14 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ Mako = "*"
parse = "*"
parse-type = "*"
pytest = ">=5.0"
typing-extensions = "*"

[tool.poetry.dev-dependencies]
tox = "^3.25.1"
mypy = "^0.961"
types-setuptools = "^57.4.18"
pytest-xdist = "^2.5.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand Down
8 changes: 4 additions & 4 deletions pytest_bdd/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from mako.lookup import TemplateLookup

from .feature import get_features
from .scenario import find_argumented_step_fixture_name, make_python_docstring, make_python_name, make_string_literal
from .scenario import find_argumented_step_function, make_python_docstring, make_python_name, make_string_literal
from .steps import get_step_fixture_name
from .types import STEP_TYPES

Expand Down Expand Up @@ -132,9 +132,9 @@ def _find_step_fixturedef(
if fixturedefs is not None:
return fixturedefs

argumented_step_name = find_argumented_step_fixture_name(name, type_, fixturemanager)
if argumented_step_name is not None:
return fixturemanager.getfixturedefs(argumented_step_name, item.nodeid)
step_func_context = find_argumented_step_function(name, type_, fixturemanager)
if step_func_context is not None:
return fixturemanager.getfixturedefs(step_func_context.name, item.nodeid)
return None


Expand Down
Loading

0 comments on commit e24aee0

Please sign in to comment.