Skip to content

Commit f309c4d

Browse files
committed
try-fix
1 parent a1d4578 commit f309c4d

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/test_formatters.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,28 +60,46 @@ def test_display_formatter_active_types_config():
6060
from IPython.terminal.interactiveshell import TerminalInteractiveShell
6161
from IPython.core.history import HistoryManager
6262
from traitlets.config import Config
63+
import tempfile
64+
import shutil
65+
import atexit
6366

6467
# Clear HistoryManager instances to bypass singleton limit before creating new shell
6568
prev_instances = HistoryManager._instances.copy()
6669
HistoryManager._instances.clear()
6770

71+
temp_dir = tempfile.mkdtemp()
6872
try:
6973
c = Config()
7074
c.DisplayFormatter.active_types = ["text/plain", "image/png"]
75+
# Use isolated history file
76+
c.HistoryManager.hist_file = f"{temp_dir}/history.sqlite"
7177

7278
ip = TerminalInteractiveShell(config=c)
7379

80+
# Remove atexit handler immediately after creation
81+
if hasattr(ip, "atexit_operations"):
82+
try:
83+
atexit.unregister(ip.atexit_operations)
84+
except ValueError:
85+
pass
86+
7487
active_types = ip.display_formatter.active_types
7588
assert "text/plain" in active_types
7689
assert "image/png" in active_types
7790

7891
# Ensure only the expected types are active
7992
assert set(active_types) == {"text/plain", "image/png"}
93+
8094
finally:
8195
# Clean up the new instance and restore previous state
8296
HistoryManager._instances.clear()
8397
HistoryManager._instances.update(prev_instances)
8498

99+
# Clean up temporary directory
100+
if temp_dir:
101+
shutil.rmtree(temp_dir, ignore_errors=True)
102+
85103

86104
def test_pretty():
87105
f = PlainTextFormatter()

0 commit comments

Comments
 (0)