def test_warning_with_small_dataloader_and_logging_interval(tmp_path):
    """Test that a warning message is shown if the dataloader length is too short for the chosen logging interval."""
    model = BoringModel()
    dataloader = DataLoader(RandomDataset(32, length=10))
    model.train_dataloader = lambda: dataloader

    with pytest.warns(UserWarning, match=r"The number of training batches \(10\) is smaller than the logging interval"):
        trainer = Trainer(default_root_dir=tmp_path, max_epochs=1, log_every_n_steps=11, logger=CSVLogger(tmp_path))
        trainer.fit(model)

    with pytest.warns(UserWarning, match=r"The number of training batches \(1\) is smaller than the logging interval"):
        trainer = Trainer(
            default_root_dir=tmp_path,
            max_epochs=1,
            log_every_n_steps=2,
            limit_train_batches=1,
            logger=CSVLogger(tmp_path),
        )
        trainer.fit(model)

    with no_warning_call(UserWarning, match="The number of training batches"):
        trainer = Trainer(default_root_dir=tmp_path, fast_dev_run=True, log_every_n_steps=2)
        trainer.fit(model)
Test that a warning message is shown if the dataloader length is too short for the chosen logging interval.
tests/tests_pytorch/trainer/test_dataloaders.py