Skip to content

Commit f1dd871

Browse files
committed
reverting change to reflect fixture moved out of class
1 parent 439bd85 commit f1dd871

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

pandas/tests/io/excel/test_writers.py

+22-22
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ def path(ext):
3232
with ensure_clean(ext) as file_path:
3333
yield file_path
3434

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+
3556

3657
@td.skip_if_no("xlrd")
3758
@pytest.mark.parametrize("ext", [".xls", ".xlsx", ".xlsm"])
@@ -252,29 +273,8 @@ def test_read_excel_parse_dates(self, ext):
252273
pytest.param("xlsxwriter", ".xlsx", marks=td.skip_if_no("xlsxwriter")),
253274
],
254275
)
276+
@pytest.mark.usefixtures("set_engine")
255277
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-
278278
def test_excel_sheet_size(self, path):
279279

280280
# GH 26080

0 commit comments

Comments
 (0)