diff --git a/allure-pytest-bdd/features/outline_converters.feature b/allure-pytest-bdd/features/outline_converters.feature new file mode 100644 index 00000000..0bae60f0 --- /dev/null +++ b/allure-pytest-bdd/features/outline_converters.feature @@ -0,0 +1,47 @@ +Feature: Scenario outline example converters + Scenario: Scenario outline example converters + Given example.feature with content: + """ + Feature: Scenario outline example converters + Scenario Outline: Outline example converters + Given step with param + + Examples: + | array | + | 0;1 | + | 2;3 | + """ + And example_test.py with content: + """ + from pytest_bdd import scenario + from pytest_bdd import given, then, when + + def param_to_array(data): + if data: + if ";" in data: + return [item for item in data.split(";")] + # case for single item that should also be returned as an array item + elif isinstance(data, str): + return [data] + else: + return [] + + @given("step with param") + def then_step_with_array(array): + pass + + @scenario("example.feature", "Outline example converters", example_converters={'array':param_to_array}) + def test_scenario_outline_example(): + pass + """ + When run pytest-bdd with allure + + Then allure report has result for "Outline example converters" scenario + Then this scenario has parameter "array" with value "['0','1']" + Then this scenario contains "Given step with <['0', '1']> param" step + + Then allure report has result for "Outline example converters" scenario + Then this scenario has parameter "array" with value "['2','3']" + Then this scenario contains "Given step with <['2', '3']> param" step + + diff --git a/allure-pytest-bdd/src/utils.py b/allure-pytest-bdd/src/utils.py index c17c1b88..81059962 100644 --- a/allure-pytest-bdd/src/utils.py +++ b/allure-pytest-bdd/src/utils.py @@ -49,4 +49,4 @@ def get_pytest_report_status(pytest_report): def get_params(node): if hasattr(node, 'callspec'): params = node.callspec.params - return [Parameter(name=name, value=value) for name, value in params.items()] + return [Parameter(name=name, value=str(value)) for name, value in params.items()] diff --git a/allure-pytest-bdd/test/outline_converters_test.py b/allure-pytest-bdd/test/outline_converters_test.py new file mode 100644 index 00000000..e28c683a --- /dev/null +++ b/allure-pytest-bdd/test/outline_converters_test.py @@ -0,0 +1,6 @@ +from pytest_bdd import scenario + + +@scenario("../features/outline_converters.feature", "Scenario outline example converters") +def test_scenario_outline(): + pass diff --git a/allure-pytest-bdd/test/steps.py b/allure-pytest-bdd/test/steps.py index db7f162c..89c2bbfc 100644 --- a/allure-pytest-bdd/test/steps.py +++ b/allure-pytest-bdd/test/steps.py @@ -1,3 +1,4 @@ +from ast import literal_eval from pytest_bdd import then from pytest_bdd import parsers from functools import partial @@ -29,6 +30,13 @@ def match(matcher, *args): return matcher() +def to_array(string): + if string.startswith("[") and string.endswith("]"): + return literal_eval(string) + else: + return string + + @then(parsers.re("allure report has result for (?:\")(?P[\\w|\\s|,]*)(?:\") scenario")) def match_scenario(allure_report, context, scenario_name): matcher = partial(match, has_test_case, scenario_name) @@ -52,14 +60,15 @@ def item_history_id(allure_report, context, item): @then(parsers.re("this (?P\\w+) " "has parameter (?:\")(?P[\\w|\\s]*)(?:\") " - "with value (?:\")(?P[\\w|\\s]*)(?:\")")) + "with value (?:\")(?P[\\w|\\s|,|\\[|\\]|<|>|']*)(?:\")"), + converters={'param_value': to_array}) def item_parameter(allure_report, context, item, param_name, param_value): context_matcher = context[item] matcher = partial(context_matcher, has_parameter, param_name, param_value) assert_that(allure_report, matcher()) -@then(parsers.re("this (?P\\w+) contains (?:\")(?P[\\w|\\s|>|<]+)(?:\") step")) +@then(parsers.re("this (?P\\w+) contains (?:\")(?P[\\w|\\s|>|<|,|\\[|\\]|']+)(?:\") step")) def step_step(allure_report, context, item, step): context_matcher = context[item] matcher = partial(context_matcher, has_step, step)