Skip to content

Commit 6002077

Browse files
committed
move get_results_dir_path to utils
1 parent 6b8ab78 commit 6002077

File tree

3 files changed

+14
-17
lines changed

3 files changed

+14
-17
lines changed

testsuite/tests/tools/conftest.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
"""Tools conftest"""
22

33
import json
4-
import os
5-
from pathlib import Path
64
import pytest
75

8-
9-
def get_results_dir_path():
10-
"""Method that gives you the path to the directory where you should store test results."""
11-
try:
12-
results_dir = os.environ.get("resultsdir")
13-
return Path(results_dir)
14-
except KeyError:
15-
current_file = Path(__file__).resolve()
16-
project_dir = current_file.parents[3]
17-
return project_dir / "attachments"
6+
from testsuite.utils import get_results_dir_path
187

198

209
def save_as_json(data, path):
@@ -34,5 +23,6 @@ def save_as_json(data, path):
3423
@pytest.hookimpl(trylast=True)
3524
def pytest_metadata(metadata):
3625
"""Saves metadata to the attachments directory in json format"""
26+
# path to resultsdir folder defaults to root of testsuite repository
3727
results_dir_path = get_results_dir_path()
38-
save_as_json(metadata, results_dir_path / "pytest_metadata.json")
28+
save_as_json(metadata, results_dir_path / "attachments" / "pytest_metadata.json")

testsuite/tests/ui/conftest.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from testsuite.ui.views.master.audience.tenant import TenantNewView, TenantDetailView
3434
from testsuite.ui.views.master.login import MasterLoginView
3535
from testsuite.ui.webdriver import ThreescaleWebdriver
36-
from testsuite.utils import blame
36+
from testsuite.utils import blame, get_results_dir_path
3737

3838

3939
LOGGER = logging.getLogger(__name__)
@@ -448,12 +448,11 @@ def get_resultsdir_path(node):
448448
"""
449449

450450
xml = node.config.getoption("--junitxml")
451-
# path to "3scape-py-testsuite" folder
452-
no_argument_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../..")
453-
resultsdir = os.environ.get("resultsdir", no_argument_dir)
454451
failed_test_name = node.nodeid.replace("/", ".").replace(".py::", ".")
455452

456453
if not xml:
454+
# path to resultsdir folder defaults to root of testsuite repository
455+
resultsdir = get_results_dir_path()
457456
path = f"{resultsdir}/attachments/ui/{failed_test_name}/"
458457

459458
else:

testsuite/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import warnings
99
from base64 import b64encode
1010
from os import urandom
11+
from pathlib import Path
1112

1213
import pytest
1314

@@ -229,3 +230,10 @@ def custom_policy() -> dict:
229230
return _M
230231
"""
231232
return {"init.lua": initlua, "example.lua": examplelua, "apicast-policy.json": apicastpolicyjson}
233+
234+
235+
def get_results_dir_path():
236+
"""resolve resultsdir or defaults to root of 3scale-tests repo"""
237+
no_argument_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../../..")
238+
resultsdir = os.environ.get("resultsdir", no_argument_dir)
239+
return Path(resultsdir)

0 commit comments

Comments
 (0)