diff --git a/allure-pytest-bdd/features/outline.feature b/allure-pytest-bdd/features/outline.feature index 2cb37e03..da75e18a 100644 --- a/allure-pytest-bdd/features/outline.feature +++ b/allure-pytest-bdd/features/outline.feature @@ -17,8 +17,9 @@ Feature: Scenario outline """ from pytest_bdd import scenario from pytest_bdd import given, then, when + from pytest_bdd.parsers import cfparse - @given(" step") + @given(cfparse("{first} step")) def given_step(first): pass @@ -26,7 +27,7 @@ Feature: Scenario outline def nope_step(): pass - @then("step with param") + @then(cfparse("step with {second} param")) def then_step(second): pass @@ -37,15 +38,11 @@ Feature: Scenario outline When run pytest-bdd with allure Then allure report has result for "Outline example" scenario - Then this scenario has parameter "first" with value "Alpha" - Then this scenario has parameter "second" with value "1" - Then this scenario contains "Given step" step - Then this scenario contains "Then step with <1> param" step + Then this scenario contains "Given Alpha step" step + Then this scenario contains "Then step with 1 param" step Then allure report has result for "Outline example" scenario - Then this scenario has parameter "first" with value "Bravo" - Then this scenario has parameter "second" with value "2" - Then this scenario contains "Given step" step - Then this scenario contains "Then step with <2> param" step + Then this scenario contains "Given Bravo step" step + Then this scenario contains "Then step with 2 param" step diff --git a/allure-pytest-bdd/setup.py b/allure-pytest-bdd/setup.py index e5ebe859..a0a3b1d4 100644 --- a/allure-pytest-bdd/setup.py +++ b/allure-pytest-bdd/setup.py @@ -20,7 +20,7 @@ install_requires = [ "pytest>=4.5.0", - "pytest-bdd>=3.0.0", + "pytest-bdd>=5.0.0", "six>=1.9.0", ] diff --git a/allure-pytest-bdd/test/conftest.py b/allure-pytest-bdd/test/conftest.py index b925ac4d..8d7e9c42 100644 --- a/allure-pytest-bdd/test/conftest.py +++ b/allure-pytest-bdd/test/conftest.py @@ -7,6 +7,8 @@ from .steps import * # noqa F401 F403 from pytest_bdd import given, when, parsers +pytest_plugins = ["pytester"] + @contextmanager def fake_logger(path, logger): diff --git a/allure-python-commons/src/logger.py b/allure-python-commons/src/logger.py index ab326b06..ecc5577a 100644 --- a/allure-python-commons/src/logger.py +++ b/allure-python-commons/src/logger.py @@ -1,13 +1,16 @@ import errno import io +import json import os +import shutil import sys -import json import uuid -import shutil -from six import text_type -from attr import asdict +from functools import partial + from allure_commons import hookimpl +from allure_commons.model2 import Parameter +from attr import asdict +from six import text_type INDENT = 4 @@ -31,7 +34,18 @@ def __init__(self, report_dir, clean=False): def _report_item(self, item): indent = INDENT if os.environ.get("ALLURE_INDENT_OUTPUT") else None filename = item.file_pattern.format(prefix=uuid.uuid4()) - data = asdict(item, filter=lambda attr, value: not (type(value) != bool and not bool(value))) + + def serializer(instance, attr, value): + if isinstance(instance, Parameter) and attr.name == 'value': + return (partial(json.dumps, indent=indent) if isinstance(value, dict) else str)(value) + else: + return value + data = asdict( + item, + filter=lambda attr, value: not (type(value) != bool and not bool(value)), + value_serializer=serializer + ) + with io.open(os.path.join(self._report_dir, filename), 'w', encoding='utf8') as json_file: if sys.version_info.major < 3: json_file.write(