def rerun_previous_test_session():
    """Trigger system testing session reusing previous settings."""
    ### if we are in play or record mode, test sessions can't be
    ### triggered, so notify user via dialog and prevent rest of
    ### method from executing by returning earlier

    if GENERAL_NS.mode_name in ('play', 'record'):

        create_and_show_dialog(CANT_TRIGGER_TESTS_DURING_PLAY_RECORD)
        return

    ### we can't trigger a test session when there are unsaved changes;
    ###
    ### notify user of that via dialog and prevent rest of method from
    ### executing by returning earlier

    if not are_changes_saved():

        create_and_show_dialog(MUST_SAVE_OR_CLOSE_TO_TRIGGER_TESTS)
        return

    ### notify user if there is no saved test settings in the user data

    if TEST_SESSION_SETTINGS_KEY not in USER_PREFS:

        create_and_show_dialog(
            "It seems you didn't run any test(s) previously."
            " Run a test session first so that its settings can"
            " be saved and reused."
        )

    ### otherwise, trigger test session after referencing the saved testing
    ### data and making appropriate checks; additional setups as also made
    ### when needed

    else:

        ### grab saved test settings
        test_settings = USER_PREFS[TEST_SESSION_SETTINGS_KEY]

        ### define a set holding the requested test case ids saved on disk
        saved_ids = set(test_settings['test_cases_ids'])

        ### define another set containing only the ids from the previous
        ### set that in fact still exist
        existing_ids = saved_ids.intersection(TEST_ID_TO_TITLE.keys())

        ### if there are saved ids that don't exist anymore, turn on
        ### a flag that causes the saved data on disk to be updated
        ### at the end of the testing session

        if saved_ids != existing_ids:
            APP_REFS.system_testing_set = True

        ### if none of the ids exist, use all available ones

        if not existing_ids:
            existing_ids.update(TEST_ID_TO_TITLE.keys())

        ### trigger system testing session

        raise (

            ResetAppException(
                mode='play',
                data={
                    'test_cases_ids': sorted(existing_ids),
                    'playback_speed': test_settings['playback_speed'],
                }
            )

        )
Trigger system testing session reusing previous settings.
nodezator/editing/playback/systemtesting.py