Skip to content

Commit d79cc2f

Browse files
authored
TST: Raise on pytest.PytestWarning (#61996)
1 parent 36b8f20 commit d79cc2f

File tree

14 files changed

+45
-15
lines changed

14 files changed

+45
-15
lines changed

.github/workflows/unit-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ jobs:
7171
# It will be temporarily activated during tests with locale.setlocale
7272
extra_loc: "zh_CN"
7373
platform: ubuntu-24.04
74-
- name: "Past no infer strings"
74+
- name: "PANDAS_FUTURE_INFER_STRING=0"
7575
env_file: actions-312.yaml
7676
pandas_future_infer_string: "0"
7777
platform: ubuntu-24.04

pandas/tests/arrays/test_datetimes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def test_simple_new_requires_match(self, unit):
100100
assert dta.dtype == dtype
101101

102102
wrong = DatetimeTZDtype("ns", "UTC")
103-
with pytest.raises(AssertionError, match=""):
103+
with pytest.raises(AssertionError, match="^$"):
104104
DatetimeArray._simple_new(arr, dtype=wrong)
105105

106106
def test_std_non_nano(self, unit):

pandas/tests/dtypes/test_dtypes.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,14 @@ def test_alias_to_unit_raises(self):
249249

250250
def test_alias_to_unit_bad_alias_raises(self):
251251
# 23990
252-
with pytest.raises(TypeError, match=""):
252+
with pytest.raises(
253+
TypeError, match="Cannot construct a 'DatetimeTZDtype' from"
254+
):
253255
DatetimeTZDtype("this is a bad string")
254256

255-
with pytest.raises(TypeError, match=""):
257+
with pytest.raises(
258+
TypeError, match="Cannot construct a 'DatetimeTZDtype' from"
259+
):
256260
DatetimeTZDtype("datetime64[ns, US/NotATZ]")
257261

258262
def test_hash_vs_equality(self, dtype):

pandas/tests/frame/test_ufunc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def test_unary_accumulate_axis():
191191

192192
def test_frame_outer_disallowed():
193193
df = pd.DataFrame({"A": [1, 2]})
194-
with pytest.raises(NotImplementedError, match=""):
194+
with pytest.raises(NotImplementedError, match="^$"):
195195
# deprecation enforced in 2.0
196196
np.subtract.outer(df, df)
197197

pandas/tests/indexes/numeric/test_indexing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,10 +585,10 @@ def test_slice_locs_na(self):
585585

586586
def test_slice_locs_na_raises(self):
587587
index = Index([np.nan, 1, 2])
588-
with pytest.raises(KeyError, match=""):
588+
with pytest.raises(KeyError, match="1.5"):
589589
index.slice_locs(start=1.5)
590590

591-
with pytest.raises(KeyError, match=""):
591+
with pytest.raises(KeyError, match="1.5"):
592592
index.slice_locs(end=1.5)
593593

594594

pandas/tests/indexes/test_base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ def test_drop_by_str_label(self, index):
712712
)
713713
@pytest.mark.parametrize("keys", [["foo", "bar"], ["1", "bar"]])
714714
def test_drop_by_str_label_raises_missing_keys(self, index, keys):
715-
with pytest.raises(KeyError, match=""):
715+
with pytest.raises(KeyError, match=".* not found in axis"):
716716
index.drop(keys)
717717

718718
@pytest.mark.parametrize(
@@ -741,7 +741,7 @@ def test_drop_by_numeric_label_loc(self):
741741

742742
def test_drop_by_numeric_label_raises_missing_keys(self):
743743
index = Index([1, 2, 3])
744-
with pytest.raises(KeyError, match=""):
744+
with pytest.raises(KeyError, match=re.escape("[4] not found in axis")):
745745
index.drop([3, 4])
746746

747747
@pytest.mark.parametrize(

pandas/tests/indexing/multiindex/test_getitem.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,12 @@ def test_series_getitem_returns_scalar(
8989
(lambda s: s[(2000, 3, 4)], KeyError, r"^\(2000, 3, 4\)$"),
9090
(lambda s: s.loc[(2000, 3, 4)], KeyError, r"^\(2000, 3, 4\)$"),
9191
(lambda s: s.loc[(2000, 3, 4, 5)], IndexingError, "Too many indexers"),
92-
(lambda s: s.__getitem__(len(s)), KeyError, ""), # match should include len(s)
93-
(lambda s: s[len(s)], KeyError, ""), # match should include len(s)
92+
(
93+
lambda s: s.__getitem__(len(s)),
94+
KeyError,
95+
"100",
96+
), # match should include len(s)
97+
(lambda s: s[len(s)], KeyError, "100"), # match should include len(s)
9498
(
9599
lambda s: s.iloc[len(s)],
96100
IndexError,

pandas/tests/io/json/test_normalize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def test_empty_array(self):
172172
)
173173
def test_accepted_input(self, data, record_path, exception_type):
174174
if exception_type is not None:
175-
with pytest.raises(exception_type, match=""):
175+
with pytest.raises(exception_type, match="^$"):
176176
json_normalize(data, record_path=record_path)
177177
else:
178178
result = json_normalize(data, record_path=record_path)

pandas/tests/io/parser/common/test_chunksize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def test_read_chunksize_and_nrows_changing_size(all_parsers):
129129
tm.assert_frame_equal(reader.get_chunk(size=2), expected.iloc[:2])
130130
tm.assert_frame_equal(reader.get_chunk(size=4), expected.iloc[2:5])
131131

132-
with pytest.raises(StopIteration, match=""):
132+
with pytest.raises(StopIteration, match="^$"):
133133
reader.get_chunk(size=3)
134134

135135

pandas/tests/io/test_sql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2226,7 +2226,7 @@ def test_api_chunksize_read(conn, request):
22262226

22272227
# reading the query in chunks with read_sql_query
22282228
if conn_name == "sqlite_buildin":
2229-
with pytest.raises(NotImplementedError, match=""):
2229+
with pytest.raises(NotImplementedError, match="^$"):
22302230
sql.read_sql_table("test_chunksize", conn, chunksize=5)
22312231
else:
22322232
res3 = DataFrame()

0 commit comments

Comments
 (0)