Skip to content

Commit

Permalink
TST Use pytest.raises instead of legacy constructs (pandas-dev#22681)
Browse files Browse the repository at this point in the history
  • Loading branch information
rth authored and victor committed Sep 30, 2018
1 parent e7898dd commit 9d069ba
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 17 deletions.
6 changes: 1 addition & 5 deletions pandas/tests/frame/test_indexing.py
Expand Up @@ -71,12 +71,8 @@ def test_getitem(self):

def test_getitem_dupe_cols(self):
df = DataFrame([[1, 2, 3], [4, 5, 6]], columns=['a', 'a', 'b'])
try:
with pytest.raises(KeyError):
df[['baf']]
except KeyError:
pass
else:
self.fail("Dataframe failed to raise KeyError")

def test_get(self):
b = self.frame.get('B')
Expand Down
6 changes: 1 addition & 5 deletions pandas/tests/plotting/test_frame.py
Expand Up @@ -588,17 +588,13 @@ def test_subplots_layout(self):
@pytest.mark.slow
def test_subplots_warnings(self):
# GH 9464
warnings.simplefilter('error')
try:
with tm.assert_produces_warning(None):
df = DataFrame(np.random.randn(100, 4))
df.plot(subplots=True, layout=(3, 2))

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

@pytest.mark.slow
def test_subplots_multiple_axes(self):
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_combine_concat.py
Expand Up @@ -28,7 +28,7 @@ def test_append(self):
elif idx in self.objSeries.index:
assert value == self.objSeries[idx]
else:
self.fail("orphaned index!")
raise AssertionError("orphaned index!")

pytest.raises(ValueError, self.ts.append, self.ts,
verify_integrity=True)
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/series/test_constructors.py
Expand Up @@ -465,7 +465,7 @@ def test_constructor_index_mismatch(self, input):
# test that construction of a Series with an index of different length
# raises an error
msg = 'Length of passed values is 3, index implies 4'
with pytest.raises(ValueError, message=msg):
with pytest.raises(ValueError, match=msg):
Series(input, index=np.arange(4))

def test_constructor_numpy_scalar(self):
Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/test_config.py
Expand Up @@ -247,12 +247,10 @@ def test_deprecate_option(self):
assert self.cf._is_deprecated('foo')
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter('always')
try:
with pytest.raises(
KeyError,
message="Nonexistent option didn't raise KeyError"):
self.cf.get_option('foo')
except KeyError:
pass
else:
self.fail("Nonexistent option didn't raise KeyError")

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

0 comments on commit 9d069ba

Please sign in to comment.