@@ -43,6 +43,13 @@ def wrapper(*args, **kwargs):
4343test_exercise = capture_test_data (test_exercise )
4444
4545
46+ @contextmanager
47+ def in_temp_dir ():
48+ with tempfile .TemporaryDirectory () as d :
49+ with ChDir (d ):
50+ yield
51+
52+
4653def run (data , run_code = True ):
4754
4855 pec = data .get ("DC_PEC" , "" )
@@ -51,30 +58,29 @@ def run(data, run_code=True):
5158 sct = data .get ("DC_SCT" , "" )
5259 force_diagnose = data .get ("DC_FORCE_DIAGNOSE" , False )
5360
54- with tempfile .TemporaryDirectory () as d :
55- with ChDir (d ):
56- if run_code :
57- sol_process , stu_process , raw_stu_output , error = run_exercise (
58- pec , sol_code , stu_code
59- )
60- else :
61- raw_stu_output = ""
62- stu_process = StubProcess () # WorkerProcess()
63- sol_process = StubProcess () # WorkerProcess()
64- error = None
65-
66- res = test_exercise (
67- sct = sct ,
68- student_code = stu_code ,
69- solution_code = sol_code ,
70- pre_exercise_code = pec ,
71- student_process = stu_process ,
72- solution_process = sol_process ,
73- raw_student_output = raw_stu_output ,
74- ex_type = "NormalExercise" ,
75- force_diagnose = force_diagnose ,
76- error = error ,
61+ with in_temp_dir ():
62+ if run_code :
63+ sol_process , stu_process , raw_stu_output , error = run_exercise (
64+ pec , sol_code , stu_code
7765 )
66+ else :
67+ raw_stu_output = ""
68+ stu_process = StubProcess () # WorkerProcess()
69+ sol_process = StubProcess () # WorkerProcess()
70+ error = None
71+
72+ res = test_exercise (
73+ sct = sct ,
74+ student_code = stu_code ,
75+ solution_code = sol_code ,
76+ pre_exercise_code = pec ,
77+ student_process = stu_process ,
78+ solution_process = sol_process ,
79+ raw_student_output = raw_stu_output ,
80+ ex_type = "NormalExercise" ,
81+ force_diagnose = force_diagnose ,
82+ error = error ,
83+ )
7884
7985 return res
8086
0 commit comments