code: def test_warn(capsys, tmp_path, monkeypatch):
      """Test the smart warn() function."""
      with pytest.warns(RuntimeWarning, match="foo"):
          warn("foo")
      captured = capsys.readouterr()
      assert captured.out == ""  # gh-5592
      assert (
          captured.err == ""
      )  # this is because pytest.warns took it already
      # test ignore_namespaces
      bad_name = tmp_path / "bad.fif"
      raw = RawArray(np.zeros((1, 1)), create_info(1, 1000.0, "eeg"))
      with pytest.warns(RuntimeWarning, match="filename") as ws:
          raw.save(bad_name)
      assert len(ws) == 1
      assert (
          "test_logging.py" in ws[0].filename
      )  # this file (it's in tests/)
  
      def warn_wrap(msg):
          warn(msg, ignore_namespaces=())
  
      monkeypatch.setattr(check, "warn", warn_wrap)
      with pytest.warns(RuntimeWarning, match="filename") as ws:
          raw.save(bad_name, overwrite=True)
  
      assert len(ws) == 1
      assert "test_logging.py" not in ws[0].filename  # this file
      assert "_logging.py" in ws[0].filename
  
imports: import logging
  import os
  import re
  import warnings
  from pathlib import Path
  import numpy
  import pytest
  from mne import Epochs, create_info, read_evokeds
  from mne.io import RawArray, read_raw_fif
  from mne.parallel import parallel_func
  from mne.utils import _get_call_line, catch_logging, check, filter_out_warnings, logger, set_log_file, set_log_level, use_log_level, verbose, warn
  from mne.utils._logging import _frame_info
label_desc: Use image node_id 7 for calling a global function with example usage: test_warn(capsys, tmp_path, monkeypatch) without return types