Skip to content

Commit 297e8be

Browse files
committed
test: change IPython session handling to avoid astropy logging issues
1 parent 0520e96 commit 297e8be

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

tests/interactive/imagetool/test_watcher.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,9 @@ def test_watcher_real(qtbot):
282282
manager.show()
283283

284284
# Start IPython session
285-
from IPython.testing.globalipapp import get_ipython
285+
from IPython.testing.globalipapp import start_ipython
286286

287-
ip_session: IPython.InteractiveShell = get_ipython()
287+
ip_session: IPython.InteractiveShell = start_ipython()
288288

289289
# Load extension
290290
ip_session.run_line_magic("load_ext", "erlab.interactive")
@@ -364,3 +364,4 @@ def test_watcher_real(qtbot):
364364
ip_session.user_ns.clear() # Clear the user namespace
365365

366366
ip_session.clear_instance()
367+
del start_ipython.already_called

tests/io/plugins/test_hers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
from typing import TYPE_CHECKING
2+
13
import pytest
24
import xarray as xr
35

46
import erlab
57

8+
if TYPE_CHECKING:
9+
import IPython
10+
611

712
@pytest.fixture(scope="module")
813
def data_dir(test_data_dir):
@@ -26,8 +31,16 @@ def expected_dir(data_dir):
2631
],
2732
)
2833
def test_load(expected_dir, args, expected) -> None:
34+
# Start IPython session to avoid astropy logging issues
35+
from IPython.testing.globalipapp import start_ipython
36+
37+
ip_session: IPython.InteractiveShell = start_ipython()
38+
2939
loaded = erlab.io.load(**args) if isinstance(args, dict) else erlab.io.load(args)
3040

3141
xr.testing.assert_identical(
3242
loaded, xr.load_dataarray(expected_dir / expected, engine="h5netcdf")
3343
)
44+
# Properly clean up the IPython session
45+
ip_session.clear_instance()
46+
del start_ipython.already_called

0 commit comments

Comments
 (0)