Skip to content

TST Replace unittest.TestCase.fail calls, use pytest.raises instead of legacy constructs #22681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions pandas/tests/frame/test_indexing.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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