From 8a314ee05e563c0dfce25c2be9ba8bc0eb9411df Mon Sep 17 00:00:00 2001 From: tligui_y Date: Sun, 3 Aug 2025 21:50:51 +0200 Subject: [PATCH] Update tests/test_utils_ipy.py --- tests/test_utils_ipy.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tests/test_utils_ipy.py b/tests/test_utils_ipy.py index 5d86d0206..c86e9e5bd 100644 --- a/tests/test_utils_ipy.py +++ b/tests/test_utils_ipy.py @@ -4,19 +4,20 @@ from slic.utils.ipy import devices from slic.core.device.device import Device import types - -@pytest.fixture(scope="module", autouse=True) -def simulate_ipython(monkeypatch): - # Simulate get_ipython() in pytest environment +# Fixture to simulate an IPython env +@pytest.fixture(scope="module") +def fake_ipython(): class FakeIPython: def __init__(self): self.user_ns = {} + return FakeIPython() - fake_ipy = FakeIPython() - monkeypatch.setattr("slic.core.device.devices.get_ipython", lambda: fake_ipy) - return fake_ipy +@pytest.fixture(autouse=True) +def simulate_ipython(fake_ipython, monkeypatch): + monkeypatch.setattr("slic.core.device.devices.get_ipython", lambda: fake_ipython) + return fake_ipython -def test_devices_repr_fallback_and_ignore(): +def test_devices_repr_fallback_and_ignore(simulate_ipython): ipy = simulate_ipython assert ipy is not None, "This test must be run in IPython (Jupyter or ipython shell)" @@ -94,4 +95,4 @@ def test_devices_repr_fallback_and_ignore(): "test_str", "test_int", "test_list", "test_func", "test_module", "test_fake_device", "_test_hidden_device" ]: - assert bad not in out + assert bad not in out \ No newline at end of file