diff --git a/allure-python-commons/src/allure_commons/utils.py b/allure-python-commons/src/allure_commons/utils.py index c50cb7ec..7714f582 100644 --- a/allure-python-commons/src/allure_commons/utils.py +++ b/allure-python-commons/src/allure_commons/utils.py @@ -200,6 +200,23 @@ def func_parameters(func, *args, **kwargs): >>> args_kwargs_varargs_keywords(1, 2, 4, d=5, e=6) [('a', '1'), ('b', '2'), ('c', '(4,)'), ('d', '5'), ('e', '6')] + >>> @helper + ... def keyword_only(a, *, b=2, c): + ... pass + + >>> keyword_only(1, c=3) + [('a', '1'), ('b', '2'), ('c', '3')] + + >>> keyword_only(1, c=3, b=4) + [('a', '1'), ('b', '4'), ('c', '3')] + + >>> @helper + ... def varargs_keyword_only(*a, b=2, **c): + ... pass + + >>> varargs_keyword_only(1, d=3) + [('a', '(1,)'), ('b', '2'), ('d', '3')] + >>> class Class: ... @staticmethod ... @helper @@ -241,6 +258,10 @@ def func_parameters(func, *args, **kwargs): varargs = args[len(arg_spec.args):] parameters.update({arg_spec.varargs: varargs} if varargs else {}) + arg_order.extend(arg_spec.kwonlyargs) + if arg_spec.kwonlydefaults: + parameters.update(arg_spec.kwonlydefaults) + if arg_spec.args and arg_spec.args[0] in ["cls", "self"]: args_dict.pop(arg_spec.args[0], None) diff --git a/tests/allure_pytest/acceptance/step/step_placeholder_test.py b/tests/allure_pytest/acceptance/step/step_placeholder_test.py index 7f93b175..1ca6d680 100644 --- a/tests/allure_pytest/acceptance/step/step_placeholder_test.py +++ b/tests/allure_pytest/acceptance/step/step_placeholder_test.py @@ -70,3 +70,27 @@ def test_args_less_than_placeholders(allure_pytest_runner: AllurePytestRunner): ) ) ) + + +def test_keyword_only_default_in_placeholder(allure_pytest_runner: AllurePytestRunner): + """ + >>> import allure + + >>> @allure.step("Wait up to {timeout} seconds") + ... def step(*, timeout=5): + ... pass + + >>> def test_keyword_only_default_in_placeholder_example(): + ... step() + """ + + allure_results = allure_pytest_runner.run_docstring() + + assert_that( + allure_results, + has_test_case( + "test_keyword_only_default_in_placeholder_example", + with_status("passed"), + has_step("Wait up to 5 seconds") + ) + )