| 1 | from __future__ import annotations |
| 2 | import importlib |
| 3 | import sys |
| 4 | from typing import Generator |
| 5 | from unittest import mock |
| 6 | import pytest |
| 7 | |
| 8 | |
| 9 | @pytest.fixture |
| 10 | def _reload_sampling() -> Generator: |
| 11 | """Ensure _sampling module is restored after tests that reload it.""" |
| 12 | import con_duct._sampling as mod |
| 13 | |
| 14 | yield |
| 15 | if hasattr(sys, "tracebacklimit"): |
| 16 | del sys.tracebacklimit |
| 17 | importlib.reload(mod) |
| 18 | |
| 19 | |
| 20 | @mock.patch("platform.system", return_value="Windows") |
| 21 | @pytest.mark.usefixtures("_reload_sampling") |
| 22 | def test_unsupported_system_raises(_mock_system: mock.MagicMock) -> None: |
| 23 | import con_duct._sampling as mod |
| 24 | |
| 25 | with pytest.raises( |
| 26 | NotImplementedError, match="does not currently support.*Windows" |
| 27 | ): |
| 28 | importlib.reload(mod) |