11import numpy as np
2- import pytest
32
43import pandas ._config .config as cf
54
@@ -120,16 +119,8 @@ def test_ambiguous_width(self):
120119
121120
122121class TestTableSchemaRepr :
123- @classmethod
124- def setup_class (cls ):
125- pytest .importorskip ("IPython" )
126-
127- from IPython .core .interactiveshell import InteractiveShell
128-
129- cls .display_formatter = InteractiveShell .instance ().display_formatter
130-
131- def test_publishes (self ):
132-
122+ def test_publishes (self , ip ):
123+ ipython = ip .instance (config = ip .config )
133124 df = pd .DataFrame ({"A" : [1 , 2 ]})
134125 objects = [df ["A" ], df , df ] # dataframe / series
135126 expected_keys = [
@@ -140,13 +131,13 @@ def test_publishes(self):
140131 opt = pd .option_context ("display.html.table_schema" , True )
141132 for obj , expected in zip (objects , expected_keys ):
142133 with opt :
143- formatted = self .display_formatter .format (obj )
134+ formatted = ipython .display_formatter .format (obj )
144135 assert set (formatted [0 ].keys ()) == expected
145136
146137 with_latex = pd .option_context ("display.latex.repr" , True )
147138
148139 with opt , with_latex :
149- formatted = self .display_formatter .format (obj )
140+ formatted = ipython .display_formatter .format (obj )
150141
151142 expected = {
152143 "text/plain" ,
@@ -156,7 +147,7 @@ def test_publishes(self):
156147 }
157148 assert set (formatted [0 ].keys ()) == expected
158149
159- def test_publishes_not_implemented (self ):
150+ def test_publishes_not_implemented (self , ip ):
160151 # column MultiIndex
161152 # GH 15996
162153 midx = pd .MultiIndex .from_product ([["A" , "B" ], ["a" , "b" , "c" ]])
@@ -165,7 +156,7 @@ def test_publishes_not_implemented(self):
165156 opt = pd .option_context ("display.html.table_schema" , True )
166157
167158 with opt :
168- formatted = self .display_formatter .format (df )
159+ formatted = ip . instance ( config = ip . config ) .display_formatter .format (df )
169160
170161 expected = {"text/plain" , "text/html" }
171162 assert set (formatted [0 ].keys ()) == expected
@@ -184,9 +175,9 @@ def test_config_default_off(self):
184175
185176 assert result is None
186177
187- def test_enable_data_resource_formatter (self ):
178+ def test_enable_data_resource_formatter (self , ip ):
188179 # GH 10491
189- formatters = self .display_formatter .formatters
180+ formatters = ip . instance ( config = ip . config ) .display_formatter .formatters
190181 mimetype = "application/vnd.dataresource+json"
191182
192183 with pd .option_context ("display.html.table_schema" , True ):
@@ -202,4 +193,4 @@ def test_enable_data_resource_formatter(self):
202193 assert "application/vnd.dataresource+json" in formatters
203194 assert formatters [mimetype ].enabled
204195 # smoke test that it works
205- self .display_formatter .format (cf )
196+ ip . instance ( config = ip . config ) .display_formatter .format (cf )
0 commit comments