Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions allure-python-commons/src/allure_commons/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
24 changes: 24 additions & 0 deletions tests/allure_pytest/acceptance/step/step_placeholder_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
)
Loading