def test_warning_on_zero_len_dataloader():
    """Test that a warning is raised if a zero-length dataloader is defined."""
    model = BoringModel()
    trainer = Trainer()
    trainer.strategy.connect(model)
    train_dataloader = DataLoader(RandomDataset(32, 0))
    val_dataloader = DataLoader(RandomDataset(32, 0))
    trainer._data_connector.attach_data(model, train_dataloaders=train_dataloader, val_dataloaders=val_dataloader)

    with pytest.warns(UserWarning, match="Total length of `CombinedLoader` across ranks is zero"):
        trainer.fit_loop.setup_data()
    assert trainer.num_training_batches == 0

    trainer.state.fn = "validate"
    with pytest.warns(UserWarning, match="Total length of `DataLoader` across ranks is zero"):
        trainer.validate_loop.setup_data()
    assert trainer.num_val_batches == [0]
Test that a warning is raised if a zero-length dataloader is defined.
tests/tests_pytorch/trainer/test_dataloaders.py