def test_import_deepspeed_lazily():
    """Test that we are importing deepspeed only when necessary."""
    code = dedent(
        """
        import lightning.fabric
        import sys

        assert 'deepspeed' not in sys.modules
        from lightning.fabric.strategies import DeepSpeedStrategy
        from lightning.fabric.plugins import DeepSpeedPrecision
        assert 'deepspeed' not in sys.modules

        import deepspeed
        assert 'deepspeed' in sys.modules
        """
    )
    # run in complete isolation
    assert subprocess.call([sys.executable, "-c", code]) == 0
Test that we are importing deepspeed only when necessary.
tests/tests_fabric/utilities/test_imports.py