MCPcopy
hub / github.com/mne-tools/mne-python / test_warn

Function test_warn

mne/utils/tests/test_logging.py:188–212  ·  view source on GitHub ↗

Test the smart warn() function.

(capsys, tmp_path, monkeypatch)

Source from the content-addressed store, hash-verified

186
187
188def test_warn(capsys, tmp_path, monkeypatch):
189 """Test the smart warn() function."""
190 with pytest.warns(RuntimeWarning, match="foo"):
191 warn("foo")
192 captured = capsys.readouterr()
193 assert captured.out == "" # gh-5592
194 assert captured.err == "" # this is because pytest.warns took it already
195 # test ignore_namespaces
196 bad_name = tmp_path / "bad.fif"
197 raw = RawArray(np.zeros((1, 1)), create_info(1, 1000.0, "eeg"))
198 with pytest.warns(RuntimeWarning, match="filename") as ws:
199 raw.save(bad_name)
200 assert len(ws) == 1
201 assert "test_logging.py" in ws[0].filename # this file (it's in tests/)
202
203 def warn_wrap(msg):
204 warn(msg, ignore_namespaces=())
205
206 monkeypatch.setattr(check, "warn", warn_wrap)
207 with pytest.warns(RuntimeWarning, match="filename") as ws:
208 raw.save(bad_name, overwrite=True)
209
210 assert len(ws) == 1
211 assert "test_logging.py" not in ws[0].filename # this file
212 assert "_logging.py" in ws[0].filename # where `mne.utils.warn` lives
213
214
215def test_get_call_line():

Callers

nothing calls this directly

Calls 4

warnFunction · 0.90
RawArrayClass · 0.90
create_infoFunction · 0.90
saveMethod · 0.45

Tested by

no test coverage detected