From 79c7d2969de918b31f6b6cb5aa6ae846da0b9d83 Mon Sep 17 00:00:00 2001 From: moink Date: Wed, 30 Dec 2020 18:48:21 +0100 Subject: [PATCH 1/2] TST: GH30999 change all pytest.raises in pandas/tests/indexing to tm.external_error_raised --- pandas/tests/indexing/multiindex/test_partial.py | 4 ++-- pandas/tests/indexing/test_coercion.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/tests/indexing/multiindex/test_partial.py b/pandas/tests/indexing/multiindex/test_partial.py index 9c356b81b85db..6e51774ee63e4 100644 --- a/pandas/tests/indexing/multiindex/test_partial.py +++ b/pandas/tests/indexing/multiindex/test_partial.py @@ -178,9 +178,9 @@ def test_partial_loc_missing(self, multiindex_year_month_day_dataframe_random_da # assert (self.ymd.loc[2000]['A'] == 0).all() # Pretty sure the second (and maybe even the first) is already wrong. - with pytest.raises(Exception): + with tm.external_error_raised(KeyError): ymd.loc[(2000, 6)] - with pytest.raises(Exception): + with tm.external_error_raised(KeyError): ymd.loc[(2000, 6), 0] # --------------------------------------------------------------------- diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index 15f58006426f4..39eac1e8ec25a 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -331,7 +331,7 @@ def test_setitem_index_float64(self, val, exp_dtype, request): if exp_dtype is IndexError: # float + int -> int temp = obj.copy() - with pytest.raises(exp_dtype): + with tm.external_error_raised(exp_dtype): temp[5] = 5 mark = pytest.mark.xfail(reason="TODO_GH12747 The result must be float") request.node.add_marker(mark) From cdbc7e482f3363a2359fc7ef5fc7cce7ff006691 Mon Sep 17 00:00:00 2001 From: moink Date: Thu, 31 Dec 2020 11:25:47 +0100 Subject: [PATCH 2/2] TST: GH30999 change all tm.external_error_raised in pandas/tests/indexing back to pytest.raises with match=msg --- pandas/tests/indexing/multiindex/test_partial.py | 4 ++-- pandas/tests/indexing/test_coercion.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pandas/tests/indexing/multiindex/test_partial.py b/pandas/tests/indexing/multiindex/test_partial.py index 6e51774ee63e4..c203d986efd23 100644 --- a/pandas/tests/indexing/multiindex/test_partial.py +++ b/pandas/tests/indexing/multiindex/test_partial.py @@ -178,9 +178,9 @@ def test_partial_loc_missing(self, multiindex_year_month_day_dataframe_random_da # assert (self.ymd.loc[2000]['A'] == 0).all() # Pretty sure the second (and maybe even the first) is already wrong. - with tm.external_error_raised(KeyError): + with pytest.raises(KeyError, match="6"): ymd.loc[(2000, 6)] - with tm.external_error_raised(KeyError): + with pytest.raises(KeyError, match="(2000, 6)"): ymd.loc[(2000, 6), 0] # --------------------------------------------------------------------- diff --git a/pandas/tests/indexing/test_coercion.py b/pandas/tests/indexing/test_coercion.py index 39eac1e8ec25a..41f967ce32796 100644 --- a/pandas/tests/indexing/test_coercion.py +++ b/pandas/tests/indexing/test_coercion.py @@ -331,7 +331,8 @@ def test_setitem_index_float64(self, val, exp_dtype, request): if exp_dtype is IndexError: # float + int -> int temp = obj.copy() - with tm.external_error_raised(exp_dtype): + msg = "index 5 is out of bounds for axis 0 with size 4" + with pytest.raises(exp_dtype, match=msg): temp[5] = 5 mark = pytest.mark.xfail(reason="TODO_GH12747 The result must be float") request.node.add_marker(mark)