Skip to content

Commit af87869

Browse files
Sup3rGeosseliverstov
authored andcommitted
bugfix windows tests (via #230)
1 parent 0d28836 commit af87869

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

allure-pytest/test/conftest.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import pytest
22
import os
3+
import sys
34
import subprocess
45
import shlex
6+
import hashlib
57
from inspect import getmembers, isfunction
68
from allure_commons_test.report import AllureReport
79
from allure_commons.utils import thread_tag
810

911

12+
def _get_hash(input):
13+
if sys.version_info < (3, 0):
14+
data = bytes(input)
15+
else:
16+
data = bytes(input, 'utf8')
17+
return hashlib.md5(data).hexdigest()
18+
19+
1020
@pytest.fixture(scope='function', autouse=True)
1121
def inject_matchers(doctest_namespace):
1222
import hamcrest
@@ -22,7 +32,8 @@ def inject_matchers(doctest_namespace):
2232
def _runner(allure_dir, module, *extra_params):
2333
FNULL = open(os.devnull, 'w')
2434
extra_params = ' '.join(extra_params)
25-
cmd = shlex.split('pytest --alluredir=%s %s %s' % (allure_dir, extra_params, module))
35+
cmd = shlex.split('pytest --alluredir=%s %s %s' % (allure_dir, extra_params, module),
36+
posix=False if os.name == "nt" else True)
2637
subprocess.call(cmd, stdout=FNULL, stderr=FNULL)
2738

2839

@@ -32,7 +43,7 @@ def allure_report_with_params(request, tmpdir_factory):
3243
tmpdir = tmpdir_factory.mktemp('data')
3344

3445
def run_with_params(*params):
35-
key = '{thread}{module}{param}'.format(thread=thread_tag(), module=module, param=''.join(params))
46+
key = _get_hash('{thread}{module}{param}'.format(thread=thread_tag(), module=module, param=''.join(params)))
3647
if not request.config.cache.get(key, False):
3748
_runner(tmpdir.strpath, module, *params)
3849
request.config.cache.set(key, True)

allure-python-commons-test/src/report.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
6767
"""
6868

69+
import sys
6970
import os
7071
import json
7172
import fnmatch
@@ -76,6 +77,10 @@
7677
from hamcrest import ends_with
7778

7879

80+
if sys.version_info[0] < 3:
81+
from io import open
82+
83+
7984
class AllureReport(object):
8085
def __init__(self, result):
8186
self.test_cases = [json.load(item) for item in self._report_items(result, '*result.json')]
@@ -86,7 +91,7 @@ def __init__(self, result):
8691
def _report_items(report_dir, glob):
8792
for _file in os.listdir(report_dir):
8893
if fnmatch.fnmatch(_file, glob):
89-
with open(os.path.join(report_dir, _file)) as report_file:
94+
with open(os.path.join(report_dir, _file), encoding="utf-8") as report_file:
9095
yield report_file
9196

9297

0 commit comments

Comments
 (0)