From 7a6335b40524a1f7ccf7618aa7c7f4e33ff624f6 Mon Sep 17 00:00:00 2001 From: Alessio Bogon <778703+youtux@users.noreply.github.com> Date: Sat, 30 Jul 2022 11:53:08 +0200 Subject: [PATCH] Simplify test --- tests/steps/test_common.py | 38 ++++++++++++++------------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/tests/steps/test_common.py b/tests/steps/test_common.py index 69c1bb07c..3ede1505e 100644 --- a/tests/steps/test_common.py +++ b/tests/steps/test_common.py @@ -9,35 +9,25 @@ @pytest.mark.parametrize("step_fn, step_type", [(given, "given"), (when, "when"), (then, "then")]) -@pytest.mark.parametrize( - "params", - [ - pytest.param({"name": "foo"}, id="simple"), - pytest.param( - { - "name": parsers.re(r"foo (?P\d+)"), - "converters": {"n": int}, - "target_fixture": "foo_n", - "stacklevel": 3, - }, - id="advanced", - ), - ], -) -def test_given_when_then_delegate_to_step(step_fn: Callable[..., Any], step_type: str, params: dict[str, Any]): +def test_given_when_then_delegate_to_step(step_fn: Callable[..., Any], step_type: str) -> None: """Test that @given, @when, @then just delegate the work to @step(...). This way we don't have to repeat integration tests for each step decorator. """ - default_params = { - "converters": None, - "target_fixture": None, - "stacklevel": 1, - } + + # Simple usage, just the step name + with mock.patch("pytest_bdd.steps.step", autospec=True) as step_mock: + step_fn("foo") + + step_mock.assert_called_once_with("foo", type_=step_type, converters=None, target_fixture=None, stacklevel=1) + + # Advanced usage: step parser, converters, target_fixture, ... with mock.patch("pytest_bdd.steps.step", autospec=True) as step_mock: - step_fn(**params) + parser = parsers.re(r"foo (?P\d+)") + step_fn(parser, converters={"n": int}, target_fixture="foo_n", stacklevel=3) - all_params = {**default_params, **params} - step_mock.assert_called_once_with(**all_params, type_=step_type) + step_mock.assert_called_once_with( + name=parser, type_=step_type, converters={"n": int}, target_fixture="foo_n", stacklevel=3 + ) def test_step_function_multiple_target_fixtures(testdir):