diff --git a/tests/test_code.py b/tests/test_code.py index 601c3f2..16f9380 100644 --- a/tests/test_code.py +++ b/tests/test_code.py @@ -348,26 +348,31 @@ def test_save_registry(self, function): """ Verifies that the CodeExercise works with an answer_registry. """ + name = "test_save_registry-student_name" + try: + + def print_success(code_ex: CodeExercise | None): + code_ex.output.object = "Success" + + cue_output = CueObject("Not initialized") + exercise_registry = ExerciseRegistry() + + code_ex = CodeExercise( + code=function, + parameters={"parameter": fixed(5)}, + exercise_registry=exercise_registry, + key="test_save_registry_ex", + outputs=[cue_output], + update=print_success, + ) - def print_success(code_ex: CodeExercise | None): - code_ex.output.object = "Success" - - cue_output = CueObject("Not initialized") - exercise_registry = ExerciseRegistry() - - code_ex = CodeExercise( - code=function, - parameters={"parameter": fixed(5)}, - exercise_registry=exercise_registry, - key="test_save_registry_ex", - outputs=[cue_output], - update=print_success, - ) - - exercise_registry._student_name_text.value = "test_save_registry-student_name" - exercise_registry.create_new_file_from_dropdown() - code_ex._save_button.click() - os.remove("test_save_registry-student_name.json") + exercise_registry._student_name_text.value = name + exercise_registry.create_new_file_from_dropdown() + code_ex._save_button.click() + finally: + file_name = f"{name}.json" + if os.path.exists(file_name): + os.remove(file_name) @pytest.mark.parametrize( "code_ex",