@@ -32,6 +32,27 @@ def path(ext):
32
32
with ensure_clean (ext ) as file_path :
33
33
yield file_path
34
34
35
+ @pytest .fixture
36
+ def set_engine (engine , ext ):
37
+ """Fixture to set engine for use in each test case.
38
+
39
+ Rather than requiring `engine=...` to be provided explicitly as an
40
+ argument in each test, this fixture sets a global option to dictate
41
+ which engine should be used to write Excel files. After executing
42
+ the test it rolls back said change to the global option.
43
+
44
+ Notes
45
+ -----
46
+ This fixture will run as part of each test method defined in the
47
+ class and any subclasses, on account of the `autouse=True`
48
+ argument
49
+ """
50
+ option_name = "io.excel.{ext}.writer" .format (ext = ext .strip ("." ))
51
+ prev_engine = get_option (option_name )
52
+ set_option (option_name , engine )
53
+ yield
54
+ set_option (option_name , prev_engine ) # Roll back option change
55
+
35
56
36
57
@td .skip_if_no ("xlrd" )
37
58
@pytest .mark .parametrize ("ext" , [".xls" , ".xlsx" , ".xlsm" ])
@@ -252,29 +273,8 @@ def test_read_excel_parse_dates(self, ext):
252
273
pytest .param ("xlsxwriter" , ".xlsx" , marks = td .skip_if_no ("xlsxwriter" )),
253
274
],
254
275
)
276
+ @pytest .mark .usefixtures ("set_engine" )
255
277
class TestExcelWriter :
256
- # Base class for test cases to run with different Excel writers.
257
- @pytest .fixture (autouse = True )
258
- def set_engine (self , engine , ext ):
259
- """Fixture to set engine for use in each test case.
260
-
261
- Rather than requiring `engine=...` to be provided explicitly as an
262
- argument in each test, this fixture sets a global option to dictate
263
- which engine should be used to write Excel files. After executing
264
- the test it rolls back said change to the global option.
265
-
266
- Notes
267
- -----
268
- This fixture will run as part of each test method defined in the
269
- class and any subclasses, on account of the `autouse=True`
270
- argument
271
- """
272
- option_name = "io.excel.{ext}.writer" .format (ext = ext .strip ("." ))
273
- prev_engine = get_option (option_name )
274
- set_option (option_name , engine )
275
- yield
276
- set_option (option_name , prev_engine ) # Roll back option change
277
-
278
278
def test_excel_sheet_size (self , path ):
279
279
280
280
# GH 26080
0 commit comments