22import sys
33from pathlib import Path
44from typing import Any
5+ import pickle
6+
57
68# This script should not have any relation to the codeflash package, be careful with imports
79cwd = 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