Skip to content

Commit 1a0cd33

Browse files
committed
reverting change to reflect fixture moved out of class
1 parent 6b778bc commit 1a0cd33

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
@@ -31,6 +31,27 @@ def path(ext):
3131
with ensure_clean(ext) as file_path:
3232
yield file_path
3333

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

3556
@td.skip_if_no("xlrd")
3657
@pytest.mark.parametrize("ext", [".xls", ".xlsx", ".xlsm"])
@@ -251,29 +272,8 @@ def test_read_excel_parse_dates(self, ext):
251272
pytest.param("xlsxwriter", ".xlsx", marks=td.skip_if_no("xlsxwriter")),
252273
],
253274
)
275+
@pytest.mark.usefixtures("set_engine")
254276
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-
277277
def test_excel_sheet_size(self, path):
278278

279279
# GH 26080

0 commit comments

Comments
 (0)