def test_warning_with_few_workers(_, tmp_path, ckpt_path, stage):
    """Test that error is raised if dataloader with only a few workers is used."""
    model = BoringModel()

    train_dl = model.train_dataloader()
    train_dl.num_workers = 0

    val_dl = model.val_dataloader()
    val_dl.num_workers = 0

    trainer = Trainer(default_root_dir=tmp_path, max_epochs=1, limit_val_batches=0.1, limit_train_batches=0.2)

    with pytest.warns(UserWarning, match=f"The '{stage}_dataloader' does not have many workers"):
        if stage == "test":
            if ckpt_path in ("specific", "best"):
                trainer.fit(model, train_dataloaders=train_dl, val_dataloaders=val_dl)
            ckpt_path = trainer.checkpoint_callback.best_model_path if ckpt_path == "specific" else ckpt_path
            trainer.test(model, dataloaders=train_dl, ckpt_path=ckpt_path)
        else:
            trainer.fit(model, train_dataloaders=train_dl, val_dataloaders=val_dl)
Test that error is raised if dataloader with only a few workers is used.
tests/tests_pytorch/trainer/test_dataloaders.py