Test the smart warn() function.
(capsys, tmp_path, monkeypatch)
| 186 | |
| 187 | |
| 188 | def 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 | |
| 215 | def test_get_call_line(): |
nothing calls this directly
no test coverage detected