def clean_import():
    """This fixture allows test to import {pytorch_}lightning* modules completely cleanly, regardless of the current
    state of the imported modules.

    Afterwards, it restores the original state of the modules.

    """
    import sys

    # copy modules to avoid modifying the original
    old_sys_modules = sys.modules
    # remove all *lightning* modules
    new_sys_modules = {key: value for key, value in sys.modules.items() if "lightning" not in key}
    sys.modules = new_sys_modules  # replace sys.modules with the new one
    yield
    sys.modules = old_sys_modules  # restore original modules
This fixture allows test to import {pytorch_}lightning* modules completely cleanly, regardless of the current
    state of the imported modules.

    Afterwards, it restores the original state of the modules.

    
tests/tests_pytorch/utilities/test_imports.py