Skip to content

Commit eed996b

Browse files
Kostiantyn GoloveshkoKostiantyn Goloveshko
authored andcommitted
Fix failing integration between Allure and pytest_bdd when test parameter is dict
1 parent 3c74fd5 commit eed996b

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

allure-python-commons/src/logger.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import errno
22
import io
3+
import json
34
import os
5+
import shutil
46
import sys
5-
import json
67
import uuid
7-
import shutil
8-
from six import text_type
9-
from attr import asdict
8+
from functools import partial
9+
1010
from allure_commons import hookimpl
11+
from allure_commons.model2 import Parameter
12+
from attr import asdict
13+
from six import text_type
1114

1215
INDENT = 4
1316

@@ -31,7 +34,18 @@ def __init__(self, report_dir, clean=False):
3134
def _report_item(self, item):
3235
indent = INDENT if os.environ.get("ALLURE_INDENT_OUTPUT") else None
3336
filename = item.file_pattern.format(prefix=uuid.uuid4())
34-
data = asdict(item, filter=lambda attr, value: not (type(value) != bool and not bool(value)))
37+
38+
def serializer(instance, attr, value):
39+
if isinstance(instance, Parameter) and attr.name == 'value':
40+
return (partial(json.dumps, indent=indent) if isinstance(value, dict) else str)(value)
41+
else:
42+
return value
43+
data = asdict(
44+
item,
45+
filter=lambda attr, value: not (type(value) != bool and not bool(value)),
46+
value_serializer=serializer
47+
)
48+
3549
with io.open(os.path.join(self._report_dir, filename), 'w', encoding='utf8') as json_file:
3650
if sys.version_info.major < 3:
3751
json_file.write(

0 commit comments

Comments
 (0)