Skip to content

Commit

Permalink
Put the remove in test test_save_registry in try-finally block (#83)
Browse files Browse the repository at this point in the history
In case the tests fail after the creation of the file but before the
remove, the file still is not removed and will make the test fail in the
next run.
  • Loading branch information
agoscinski authored Dec 21, 2024
1 parent fe978ca commit eec8088
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions tests/test_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit eec8088

Please sign in to comment.