@@ -1029,6 +1029,18 @@ def test_read_excel_squeeze(self, ext):
10291029 tm .assert_series_equal (actual , expected )
10301030
10311031
1032+ class _WriterBase (SharedItems ):
1033+ """Provides fixture to set / reset options for all writer tests"""
1034+
1035+ @pytest .fixture (autouse = True )
1036+ def set_options (self , request , merge_cells , engine , ext ):
1037+ option_name = 'io.excel.{ext}.writer' .format (ext = ext .strip ('.' ))
1038+ prev_engine = get_option (option_name )
1039+ set_option (option_name , engine )
1040+ yield
1041+ set_option (option_name , prev_engine )
1042+
1043+
10321044@pytest .mark .parametrize ("merge_cells" , [True , False ])
10331045@pytest .mark .parametrize ("engine,ext" , [
10341046 pytest .param ('openpyxl' , '.xlsx' , marks = pytest .mark .skipif (
@@ -1038,9 +1050,8 @@ def test_read_excel_squeeze(self, ext):
10381050 pytest .param ('xlsxwriter' , '.xlsx' , marks = pytest .mark .skipif (
10391051 not td .safe_import ('xlsxwriter' ), reason = 'No xlsxwriter' ))
10401052])
1041- class TestExcelWriter (SharedItems ):
1053+ class TestExcelWriter (_WriterBase ):
10421054 # Base class for test cases to run with different Excel writers.
1043- merge_cells = True
10441055
10451056 def test_excel_sheet_by_name_raise (self , merge_cells , engine , ext ):
10461057 import xlrd
@@ -1935,10 +1946,11 @@ def test_path_localpath(self, merge_cells, engine, ext):
19351946
19361947
19371948@td .skip_if_no ('openpyxl' )
1938- @pytest .mark .parametrize ("ext" , ['.xlsx' ])
1939- class TestOpenpyxlTests (SharedItems ):
1949+ @pytest .mark .parametrize ("merge_cells,ext,engine" , [
1950+ (None , '.xlsx' , 'openpyxl' )])
1951+ class TestOpenpyxlTests (_WriterBase ):
19401952
1941- def test_to_excel_styleconverter (self , ext ):
1953+ def test_to_excel_styleconverter (self , merge_cells , ext , engine ):
19421954 from openpyxl import styles
19431955
19441956 hstyle = {
@@ -1992,7 +2004,7 @@ def test_to_excel_styleconverter(self, ext):
19922004 assert kw ['number_format' ] == number_format
19932005 assert kw ['protection' ] == protection
19942006
1995- def test_write_cells_merge_styled (self , ext ):
2007+ def test_write_cells_merge_styled (self , merge_cells , ext , engine ):
19962008 from pandas .io .formats .excel import ExcelCell
19972009
19982010 sheet_name = 'merge_styled'
@@ -2026,10 +2038,12 @@ def test_write_cells_merge_styled(self, ext):
20262038
20272039
20282040@td .skip_if_no ('xlwt' )
2029- @pytest .mark .parametrize ("ext" , ['.xls' ])
2030- class TestXlwtTests (SharedItems ):
2041+ @pytest .mark .parametrize ("merge_cells,ext,engine" , [
2042+ (None , '.xls' , 'xlwt' )])
2043+ class TestXlwtTests (_WriterBase ):
20312044
2032- def test_excel_raise_error_on_multiindex_columns_and_no_index (self , ext ):
2045+ def test_excel_raise_error_on_multiindex_columns_and_no_index (
2046+ self , merge_cells , ext , engine ):
20332047 # MultiIndex as columns is not yet implemented 9794
20342048 cols = MultiIndex .from_tuples ([('site' , '' ),
20352049 ('2014' , 'height' ),
@@ -2039,15 +2053,16 @@ def test_excel_raise_error_on_multiindex_columns_and_no_index(self, ext):
20392053 with ensure_clean (ext ) as path :
20402054 df .to_excel (path , index = False )
20412055
2042- def test_excel_multiindex_columns_and_index_true (self , ext ):
2056+ def test_excel_multiindex_columns_and_index_true (self , merge_cells , ext ,
2057+ engine ):
20432058 cols = MultiIndex .from_tuples ([('site' , '' ),
20442059 ('2014' , 'height' ),
20452060 ('2014' , 'weight' )])
20462061 df = pd .DataFrame (np .random .randn (10 , 3 ), columns = cols )
20472062 with ensure_clean (ext ) as path :
20482063 df .to_excel (path , index = True )
20492064
2050- def test_excel_multiindex_index (self , ext ):
2065+ def test_excel_multiindex_index (self , merge_cells , ext , engine ):
20512066 # MultiIndex as index works so assert no error #9794
20522067 cols = MultiIndex .from_tuples ([('site' , '' ),
20532068 ('2014' , 'height' ),
@@ -2056,7 +2071,7 @@ def test_excel_multiindex_index(self, ext):
20562071 with ensure_clean (ext ) as path :
20572072 df .to_excel (path , index = False )
20582073
2059- def test_to_excel_styleconverter (self , ext ):
2074+ def test_to_excel_styleconverter (self , merge_cells , ext , engine ):
20602075 import xlwt
20612076
20622077 hstyle = {"font" : {"bold" : True },
@@ -2077,10 +2092,11 @@ def test_to_excel_styleconverter(self, ext):
20772092
20782093
20792094@td .skip_if_no ('xlsxwriter' )
2080- @pytest .mark .parametrize ("ext" , ['.xlsx' ])
2081- class TestXlsxWriterTests (SharedItems ):
2095+ @pytest .mark .parametrize ("merge_cells,ext,engine" , [
2096+ (None , '.xlsx' , 'xlsxwriter' )])
2097+ class TestXlsxWriterTests (_WriterBase ):
20822098
2083- def test_column_format (self , ext ):
2099+ def test_column_format (self , merge_cells , ext , engine ):
20842100 # Test that column formats are applied to cells. Test for issue #9167.
20852101 # Applicable to xlsxwriter only.
20862102 with warnings .catch_warnings ():
0 commit comments