Skip to content

Commit 74af4b6

Browse files
author
Damien Barker
committed
QPR-12959 update conftests
1 parent 795d903 commit 74af4b6

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Examples/conftest.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# conftest.py
2+
import pytest, os, sys
3+
from pathlib import Path
4+
script_dir = Path(__file__).parents[0]
5+
sys.path.append(os.path.join(script_dir, '../Tools/PythonTools'))
6+
from update_expected_output import copy_existing_files
7+
8+
9+
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
10+
def pytest_runtest_makereport(item, call):
11+
outcome = yield
12+
report = outcome.get_result()
13+
14+
# Only proceed during the "call" phase
15+
if report.when != "call":
16+
return
17+
18+
# Read environment variables
19+
copy_all_output = os.getenv("UPDATE_ALL_EXPECTED_OUTPUT", "").upper() == "TRUE"
20+
copy_failed_output = os.getenv("UPDATE_FAILED_EXPECTED_OUTPUT", "").upper() == "TRUE"
21+
22+
# Logic:
23+
# - UPDATE_ALL_EXPECTED_OUTPUT → always copy
24+
# - UPDATE_FAILED_EXPECTED_OUTPUT → copy only if test failed
25+
if copy_all_output or (copy_failed_output and report.failed):
26+
# Build test path
27+
test_name = item.name
28+
test_name = test_name.replace('-', '/', 1)
29+
test_path = Path(item.config.rootdir) / test_name
30+
31+
copy_existing_files(test_path)
32+
33+
34+

0 commit comments

Comments
 (0)