diff --git a/pandas/tests/frame/test_indexing.py b/pandas/tests/frame/test_indexing.py index f0c4d7be2f293..96b2e98dd7e8d 100644 --- a/pandas/tests/frame/test_indexing.py +++ b/pandas/tests/frame/test_indexing.py @@ -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') diff --git a/pandas/tests/plotting/test_frame.py b/pandas/tests/plotting/test_frame.py index 47a93ba82d77b..05c5f5a14b7a1 100644 --- a/pandas/tests/plotting/test_frame.py +++ b/pandas/tests/plotting/test_frame.py @@ -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(Warning): 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): @@ -1250,7 +1246,7 @@ def test_plot_bar(self): _check_plot_works(df.plot.bar) _check_plot_works(df.plot.bar, legend=False) # _check_plot_works adds an ax so catch warning. see GH #13188 - with tm.assert_produces_warning(UserWarning): + with tm.assert_produces_warning(None): _check_plot_works(df.plot.bar, subplots=True) _check_plot_works(df.plot.bar, stacked=True) diff --git a/pandas/tests/series/test_combine_concat.py b/pandas/tests/series/test_combine_concat.py index f8420b302836e..35ba4fbf0ce25 100644 --- a/pandas/tests/series/test_combine_concat.py +++ b/pandas/tests/series/test_combine_concat.py @@ -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) diff --git a/pandas/tests/series/test_constructors.py b/pandas/tests/series/test_constructors.py index d2fbd69a2a08f..9faf47ace242d 100644 --- a/pandas/tests/series/test_constructors.py +++ b/pandas/tests/series/test_constructors.py @@ -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): diff --git a/pandas/tests/test_config.py b/pandas/tests/test_config.py index 91ce65dcce9b2..fd8e98c483f78 100644 --- a/pandas/tests/test_config.py +++ b/pandas/tests/test_config.py @@ -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