code: def test_check_val_every_n_epoch(
      tmpdir, max_epochs, expected_val_loop_calls, expected_val_batches
  ):
      class TestModel(BoringModel):
          val_epoch_calls = 0
          val_batches = []
  
          def on_train_epoch_end(self, *args, **kwargs):
              self.val_batches.append(
                  self.trainer.progress_bar_callback.total_val_batches
              )
  
          def on_validation_epoch_start(self) -> None:
              self.val_epoch_calls += 1
  
      model = TestModel()
      trainer = Trainer(
          default_root_dir=tmpdir,
          max_epochs=max_epochs,
          num_sanity_val_steps=0,
          limit_val_batches=2,
          check_val_every_n_epoch=2,
          logger=False,
      )
      trainer.fit(model)
      assert (
          trainer.state.finished
      ), f"Training failed with {trainer.state}"
  
      assert model.val_epoch_calls == expected_val_loop_calls
      assert model.val_batches == expected_val_batches
  
imports: import pytest
  from lightning.pytorch.demos.boring_classes import BoringModel, RandomDataset
  from lightning.pytorch.trainer.trainer import Trainer
  from torch.utils.data import DataLoader
label_desc: Use image node_id 1 for calling a global function with example usage: test_check_val_every_n_epoch(tmpdir, max_epochs, expected_val_loop_calls, expected_val_batches) without return types