Skip to content

Commit 3a3e0b3

Browse files
committed
test: discard OLED residue from skipped cases
1 parent 314cfe7 commit 3a3e0b3

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import glob
1515
import hashlib
1616
import json
17+
import shutil
1718
import socket
1819
import sys
1920

@@ -50,6 +51,23 @@ def pytest_collection_modifyitems(config, items):
5051
config.hook.pytest_deselected(items=deselected)
5152
items[:] = selected
5253

54+
55+
def _screenshot_dir_for_item(item):
56+
module = os.path.splitext(os.path.basename(item.location[0]))[0]
57+
method = getattr(item, 'originalname', None) or item.name.split('[', 1)[0]
58+
return os.path.join(
59+
os.environ.get('SCREENSHOT_DIR', 'screenshots'),
60+
module.replace('test_', '', 1), method)
61+
62+
63+
@pytest.hookimpl(hookwrapper=True)
64+
def pytest_runtest_makereport(item, call):
65+
"""A skipped case must never retain setup/policy frames as evidence."""
66+
outcome = yield
67+
report = outcome.get_result()
68+
if (os.environ.get('KEEPKEY_SCREENSHOT') == '1' and report.skipped):
69+
shutil.rmtree(_screenshot_dir_for_item(item), ignore_errors=True)
70+
5371
if os.environ.get('KEEPKEY_SCREENSHOT') == '1':
5472
import common
5573

0 commit comments

Comments
 (0)