Skip to content

Commit 9d069ba

Browse files
rthvictor
authored and
victor
committed
TST Use pytest.raises instead of legacy constructs (pandas-dev#22681)
1 parent e7898dd commit 9d069ba

File tree

5 files changed

+7
-17
lines changed

5 files changed

+7
-17
lines changed

pandas/tests/frame/test_indexing.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,8 @@ def test_getitem(self):
7171

7272
def test_getitem_dupe_cols(self):
7373
df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=['a', 'a', 'b'])
74-
try:
74+
with pytest.raises(KeyError):
7575
df[['baf']]
76-
except KeyError:
77-
pass
78-
else:
79-
self.fail("Dataframe failed to raise KeyError")
8076

8177
def test_get(self):
8278
b = self.frame.get('B')

pandas/tests/plotting/test_frame.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -588,17 +588,13 @@ def test_subplots_layout(self):
588588
@pytest.mark.slow
589589
def test_subplots_warnings(self):
590590
# GH 9464
591-
warnings.simplefilter('error')
592-
try:
591+
with tm.assert_produces_warning(None):
593592
df = DataFrame(np.random.randn(100, 4))
594593
df.plot(subplots=True, layout=(3, 2))
595594

596595
df = DataFrame(np.random.randn(100, 4),
597596
index=date_range('1/1/2000', periods=100))
598597
df.plot(subplots=True, layout=(3, 2))
599-
except Warning as w:
600-
self.fail(w)
601-
warnings.simplefilter('default')
602598

603599
@pytest.mark.slow
604600
def test_subplots_multiple_axes(self):

pandas/tests/series/test_combine_concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_append(self):
2828
elif idx in self.objSeries.index:
2929
assert value == self.objSeries[idx]
3030
else:
31-
self.fail("orphaned index!")
31+
raise AssertionError("orphaned index!")
3232

3333
pytest.raises(ValueError, self.ts.append, self.ts,
3434
verify_integrity=True)

pandas/tests/series/test_constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def test_constructor_index_mismatch(self, input):
465465
# test that construction of a Series with an index of different length
466466
# raises an error
467467
msg = 'Length of passed values is 3, index implies 4'
468-
with pytest.raises(ValueError, message=msg):
468+
with pytest.raises(ValueError, match=msg):
469469
Series(input, index=np.arange(4))
470470

471471
def test_constructor_numpy_scalar(self):

pandas/tests/test_config.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,10 @@ def test_deprecate_option(self):
247247
assert self.cf._is_deprecated('foo')
248248
with warnings.catch_warnings(record=True) as w:
249249
warnings.simplefilter('always')
250-
try:
250+
with pytest.raises(
251+
KeyError,
252+
message="Nonexistent option didn't raise KeyError"):
251253
self.cf.get_option('foo')
252-
except KeyError:
253-
pass
254-
else:
255-
self.fail("Nonexistent option didn't raise KeyError")
256254

257255
assert len(w) == 1 # should have raised one warning
258256
assert 'deprecated' in str(w[-1]) # we get the default message

0 commit comments

Comments
 (0)