@@ -18,25 +18,22 @@ def helpers():
1818 Fixture that renders the helpers.py.template to a real Python module
1919 and makes it importable for both parent and child processes.
2020 """
21- # Create a temporary directory and copy the template as a real Python module
22- temp_dir = tempfile .mkdtemp ()
23- template_path = Path (
24- "grandchallenge/forge/templates/forge/partials/example_evaluation_method/helpers.py.template"
25- )
26- helpers_path = Path (temp_dir ) / "helpers.py"
27- shutil .copy (template_path , helpers_path )
21+ with tempfile .TemporaryDirectory () as temp_dir :
22+ template_path = Path (
23+ "grandchallenge/forge/templates/forge/partials/example_evaluation_method/helpers.py.template"
24+ )
25+ helpers_path = Path (temp_dir ) / "helpers.py"
2826
29- # Add temp directory to sys.path so child processes can import it
30- sys .path .insert (0 , temp_dir )
27+ shutil .copy (template_path , helpers_path )
3128
32- # Now import it normally
33- import helpers as helpers_module
29+ try :
30+ sys . path . insert ( 0 , temp_dir )
3431
35- yield helpers_module
32+ import helpers as helpers_module
3633
37- # Cleanup: remove from sys.path and delete temp directory
38- sys . path . remove ( temp_dir )
39- shutil . rmtree (temp_dir , ignore_errors = True )
34+ yield helpers_module
35+ finally :
36+ sys . path . remove (temp_dir )
4037
4138
4239def working_process (p ):
0 commit comments