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