I was trying to make a script of mine save some data before it exits. I looked at the atexit documentation and I was wondering if there is a way to test the code gets executed when the process is terminated (more specifically, using pytest). Maybe there is no point in doing it, but is it possible? Here is my code
method that atexit calls
@classmethod
def save_state(cls, program_state, program_manager):
running = program_state.get_curr_running()
print("Saving the current state upon exit...")
pruned = program_manager.prune_programs(running)
for pg in pruned:
pg.end_now()
DataManager.update_pg_times(pruned)
# Before the program is shutdown, currently running programs are updated
import atexit
atexit.register(DataManager.save_state, program_state, program_manager)