diff --git a/pandas/tests/frame/test_query_eval.py b/pandas/tests/frame/test_query_eval.py index abd8ef98ff871..d577ff7c71277 100644 --- a/pandas/tests/frame/test_query_eval.py +++ b/pandas/tests/frame/test_query_eval.py @@ -479,11 +479,13 @@ def test_query_scope(self): tm.assert_frame_equal(res, expected) # no local variable c - with pytest.raises(UndefinedVariableError): + with pytest.raises( + UndefinedVariableError, match="local variable 'c' is not defined" + ): df.query("@a > b > @c", engine=engine, parser=parser) # no column named 'c' - with pytest.raises(UndefinedVariableError): + with pytest.raises(UndefinedVariableError, match="name 'c' is not defined"): df.query("@a > b > c", engine=engine, parser=parser) def test_query_doesnt_pickup_local(self): @@ -494,7 +496,7 @@ def test_query_doesnt_pickup_local(self): df = DataFrame(np.random.randint(m, size=(n, 3)), columns=list("abc")) # we don't pick up the local 'sin' - with pytest.raises(UndefinedVariableError): + with pytest.raises(UndefinedVariableError, match="name 'sin' is not defined"): df.query("sin > 5", engine=engine, parser=parser) def test_query_builtin(self): @@ -588,7 +590,7 @@ def test_nested_raises_on_local_self_reference(self): df = DataFrame(np.random.randn(5, 3)) # can't reference ourself b/c we're a local so @ is necessary - with pytest.raises(UndefinedVariableError): + with pytest.raises(UndefinedVariableError, match="name 'df' is not defined"): df.query("df > 0", engine=self.engine, parser=self.parser) def test_local_syntax(self): @@ -651,9 +653,9 @@ def test_query_undefined_local(self): skip_if_no_pandas_parser(parser) df = DataFrame(np.random.rand(10, 2), columns=list("ab")) - msg = "local variable 'c' is not defined" - - with pytest.raises(UndefinedVariableError, match=msg): + with pytest.raises( + UndefinedVariableError, match="local variable 'c' is not defined" + ): df.query("a == @c", engine=engine, parser=parser) def test_index_resolvers_come_after_columns_with_the_same_name(self): @@ -784,7 +786,7 @@ def test_nested_scope(self): with pytest.raises(SyntaxError): df.query("(@df>0) & (@df2>0)", engine=engine, parser=parser) - with pytest.raises(UndefinedVariableError): + with pytest.raises(UndefinedVariableError, match="name 'df' is not defined"): df.query("(df>0) & (df2>0)", engine=engine, parser=parser) expected = df[(df > 0) & (df2 > 0)]