Skip to content

Commit c7a4512

Browse files
committed
Fix conftest.py cleanup to handle missing cwd in Python 3.14
Python 3.14's os.path.abspath() throws FileNotFoundError when the current working directory doesn't exist. This happens when tests change directory to a temp directory that gets deleted. Wrap the cleanup code in try-except to gracefully handle cleanup failures. Fixes INTERNALERROR during test cleanup phase.
1 parent 0a9e954 commit c7a4512

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

tests/conftest.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ def pytest_exception_interact(node, call, report):
1212
"""See https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_exception_interact""" # noqa: E501
1313
if report.failed:
1414
# Clean up temp dirs in tests/test_repo if a test failed.
15-
if os.path.exists("tests/test_repo/temp"):
16-
shutil.rmtree("tests/test_repo/temp")
17-
# Delete generated files
18-
for filename in ["ok.plist", "err.plist", "defaults.cfg"]:
19-
abs_filename = os.path.abspath(filename)
20-
if os.path.exists(abs_filename):
21-
os.remove(abs_filename)
15+
try:
16+
if os.path.exists("tests/test_repo/temp"):
17+
shutil.rmtree("tests/test_repo/temp")
18+
# Delete generated files
19+
for filename in ["ok.plist", "err.plist", "defaults.cfg"]:
20+
abs_filename = os.path.abspath(filename)
21+
if os.path.exists(abs_filename):
22+
os.remove(abs_filename)
23+
except (FileNotFoundError, OSError):
24+
# Cleanup failed (e.g., cwd doesn't exist), ignore
25+
pass
2226

2327

2428
def pytest_generate_tests(metafunc):

0 commit comments

Comments
 (0)