def test_tqdm_total_steps_with_iterator_no_length(tmp_path, max_steps):
    """Test trainer with infinite iterator (no __len__)"""

    batch_size = 4
    model = BoringModel()

    # Infinite generator (no __len__)
    # NOTE: 32 for BoringModel
    infinite_iter = (torch.randn(batch_size, 32, dtype=torch.float32) for _ in itertools.count(0))

    trainer = Trainer(
        default_root_dir=tmp_path,
        max_steps=max_steps,
        max_epochs=-1,
        limit_val_batches=0,
        enable_progress_bar=True,
        enable_model_summary=False,
        accelerator="cpu",
    )

    # Override train_dataloader with infinite iterator
    model.train_dataloader = lambda: infinite_iter
    pbar = trainer.progress_bar_callback
    trainer.fit(model)

    # assert progress bar callback uses correct total steps
    assert pbar.train_progress_bar.total == max_steps
Test trainer with infinite iterator (no __len__)
tests/tests_pytorch/loops/test_training_loop.py