diff --git a/pandas/tests/indexing/test_chaining_and_caching.py b/pandas/tests/indexing/test_chaining_and_caching.py index 66835c586e6c7..1254f1f217a2e 100644 --- a/pandas/tests/indexing/test_chaining_and_caching.py +++ b/pandas/tests/indexing/test_chaining_and_caching.py @@ -335,12 +335,14 @@ def test_setting_with_copy_bug(self): # this should not raise df2["y"] = ["g", "h", "i"] - def test_detect_chained_assignment_warnings(self): + def test_detect_chained_assignment_warnings_errors(self): + df = DataFrame({"A": ["aaa", "bbb", "ccc"], "B": [1, 2, 3]}) with option_context("chained_assignment", "warn"): - df = DataFrame({"A": ["aaa", "bbb", "ccc"], "B": [1, 2, 3]}) - with tm.assert_produces_warning(com.SettingWithCopyWarning): df.loc[0]["A"] = 111 + with option_context("chained_assignment", "raise"): + with pytest.raises(com.SettingWithCopyError): + df.loc[0]["A"] = 111 def test_detect_chained_assignment_warnings_filter_and_dupe_cols(self): # xref gh-13017.