Update tests/test_utils_ipy.py
Run CI Tests / test (push) Successful in 54s

This commit is contained in:
2025-08-03 21:50:51 +02:00
parent 30a5203064
commit 8a314ee05e
+9 -8
View File
@@ -4,19 +4,20 @@ from slic.utils.ipy import devices
from slic.core.device.device import Device from slic.core.device.device import Device
import types import types
# Fixture to simulate an IPython env
@pytest.fixture(scope="module", autouse=True) @pytest.fixture(scope="module")
def simulate_ipython(monkeypatch): def fake_ipython():
# Simulate get_ipython() in pytest environment
class FakeIPython: class FakeIPython:
def __init__(self): def __init__(self):
self.user_ns = {} self.user_ns = {}
return FakeIPython()
fake_ipy = FakeIPython() @pytest.fixture(autouse=True)
monkeypatch.setattr("slic.core.device.devices.get_ipython", lambda: fake_ipy) def simulate_ipython(fake_ipython, monkeypatch):
return fake_ipy 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 ipy = simulate_ipython
assert ipy is not None, "This test must be run in IPython (Jupyter or ipython shell)" assert ipy is not None, "This test must be run in IPython (Jupyter or ipython shell)"