def test_dm_reload_dataloaders_every_n_epochs(tmp_path):
    """Test datamodule, where trainer argument reload_dataloaders_every_n_epochs is set to a non negative integer."""

    class CustomBoringDataModule(BoringDataModule):
        def __init__(self):
            super().__init__()
            self._epochs_called_for = []

        def train_dataloader(self):
            assert self.trainer.current_epoch not in self._epochs_called_for
            self._epochs_called_for.append(self.trainer.current_epoch)
            return super().train_dataloader()

    dm = CustomBoringDataModule()
    model = BoringModel()

    model.validation_step = None
    model.test_step = None

    trainer = Trainer(
        default_root_dir=tmp_path, max_epochs=3, limit_train_batches=2, reload_dataloaders_every_n_epochs=2
    )
    trainer.fit(model, dm)
Test datamodule, where trainer argument reload_dataloaders_every_n_epochs is set to a non negative integer.
tests/tests_pytorch/core/test_datamodules.py