Skip to content

Commit 41c4aff

Browse files
cruzzoeroberthdevries
authored andcommitted
Changes to test to prevent warnings in tests
1 parent 6bb95ab commit 41c4aff

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

pandas/tests/io/excel/test_xlrd.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import warnings
2+
13
import pytest
24

35
import pandas as pd
@@ -26,7 +28,6 @@ def test_read_xlrd_book(read_ext, frame):
2628
with tm.ensure_clean(read_ext) as pth:
2729
df.to_excel(pth, sheet_name)
2830
book = xlrd.open_workbook(pth)
29-
3031
with ExcelFile(book, engine=engine) as xl:
3132
result = pd.read_excel(xl, sheet_name=sheet_name, index_col=0)
3233
tm.assert_frame_equal(df, result)
@@ -38,20 +39,24 @@ def test_read_xlrd_book(read_ext, frame):
3839
# TODO: test for openpyxl as well
3940
def test_excel_table_sheet_by_index(datapath, read_ext):
4041
path = datapath("io", "data", "excel", f"test1{read_ext}")
41-
with pd.ExcelFile(path) as excel:
42-
with pytest.raises(xlrd.XLRDError):
43-
pd.read_excel(excel, sheet_name="asdf")
42+
with warnings.catch_warnings():
43+
warnings.simplefilter("ignore")
44+
with pd.ExcelFile(path) as excel:
45+
with pytest.raises(xlrd.XLRDError):
46+
pd.read_excel(excel, sheet_name="asdf")
4447

4548

4649
# See issue #29375
4750
def test_excel_file_warning_with_default_engine(datapath):
48-
path = datapath("io", "data", "test1.xls")
49-
with tm.assert_produces_warning(FutureWarning):
51+
path = datapath("io", "data", "excel", "test1.xls")
52+
with warnings.catch_warnings(record=True) as w:
5053
pd.ExcelFile(path)
54+
assert "default to \"openpyxl\" in the future." in str(w[-1].message)
5155

5256

5357
# See issue #29375
5458
def test_read_excel_warning_with_default_engine(tmpdir, datapath):
55-
path = datapath("io", "data", "test1.xls")
56-
with tm.assert_produces_warning(FutureWarning):
57-
pd.read_excel(path, sheet_name="Sheet1")
59+
path = datapath("io", "data", "excel", "test1.xls")
60+
with warnings.catch_warnings(record=True) as w:
61+
pd.read_excel(path, "Sheet1")
62+
assert "default to \"openpyxl\" in the future." in str(w[-1].message)

0 commit comments

Comments
 (0)