Skip to content

Commit 1202963

Browse files
committed
resolve review suggestions
1 parent 5af2f61 commit 1202963

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

codeflash/discovery/pytest_new_process_discovery.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
import sys
33
from pathlib import Path
44
from typing import Any
5+
import pickle
6+
57

68
# This script should not have any relation to the codeflash package, be careful with imports
79
cwd = sys.argv[1]
@@ -31,10 +33,9 @@ def pytest_collection_finish(self, session) -> None:
3133

3234
# Write results immediately since pytest.main() will exit after this callback, not always with a success code
3335
tests = parse_pytest_collection_results(collected_tests)
36+
exit_code = getattr(session.config, "exitstatus", 0)
3437
with Path(pickle_path).open("wb") as f:
35-
import pickle
36-
37-
pickle.dump((0, tests, pytest_rootdir), f, protocol=pickle.HIGHEST_PROTOCOL)
38+
pickle.dump((exit_code, tests, pytest_rootdir), f, protocol=pickle.HIGHEST_PROTOCOL)
3839

3940
def pytest_collection_modifyitems(self, items) -> None:
4041
skip_benchmark = pytest.mark.skip(reason="Skipping benchmark tests")
@@ -53,3 +54,8 @@ def pytest_collection_modifyitems(self, items) -> None:
5354
)
5455
except Exception as e:
5556
print(f"Failed to collect tests: {e!s}")
57+
try:
58+
with Path(pickle_path).open("wb") as f:
59+
pickle.dump((1, [], None), f, protocol=pickle.HIGHEST_PROTOCOL)
60+
except Exception as pickle_error:
61+
print(f"Failed to write failure pickle: {pickle_error!s}", file=sys.stderr)

0 commit comments

Comments
 (0)