Skip to content

Commit 64c38bc

Browse files
authored
Make log collection more resilient (#42)
As we observed that sometimes log collection can fail due to source folder being removed, we just log these failures as warnings.
1 parent fd8fb03 commit 64c38bc

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/pytest_plus/__init__.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,16 @@ def pytest_sessionfinish(session: pytest.Session) -> None:
5353
# copy all pytest own logs inside $VIRTUAL_ENV/log, for collection.
5454
venv = os.environ.get("VIRTUAL_ENV", "")
5555
if os.environ.get("CI", "0") != "0" and venv:
56-
shutil.copytree(
57-
src=session.config._tmp_path_factory.getbasetemp(), # type: ignore[attr-defined] # noqa: SLF001
58-
dst=venv + "/log",
59-
dirs_exist_ok=True,
60-
)
56+
# Copy can fail if the source folder was already removed, but we
57+
# should not fail due to this.
58+
try:
59+
shutil.copytree(
60+
src=session.config._tmp_path_factory.getbasetemp(), # type: ignore[attr-defined] # noqa: SLF001
61+
dst=venv + "/log",
62+
dirs_exist_ok=True,
63+
)
64+
except OSError as e:
65+
_logger.warning("Failed to copy pytest logs to $VIRTUAL_ENV/log: %s", e)
6166

6267

6368
@pytest.hookimpl(tryfirst=True) # type: ignore[misc,unused-ignore]

0 commit comments

Comments
 (0)