diff --git a/pandas/tests/scalar/test_nat.py b/pandas/tests/scalar/test_nat.py index 2ea7602b00206..5dc0c40ef42dd 100644 --- a/pandas/tests/scalar/test_nat.py +++ b/pandas/tests/scalar/test_nat.py @@ -558,20 +558,28 @@ def test_nat_comparisons_numpy(other): assert not NaT >= other -@pytest.mark.parametrize("other", ["foo", 2, 2.0]) -@pytest.mark.parametrize("op", [operator.le, operator.lt, operator.ge, operator.gt]) -def test_nat_comparisons_invalid(other, op): +@pytest.mark.parametrize("other_and_type", [("foo", "str"), (2, "int"), (2.0, "float")]) +@pytest.mark.parametrize( + "symbol_and_op", + [("<=", operator.le), ("<", operator.lt), (">=", operator.ge), (">", operator.gt)], +) +def test_nat_comparisons_invalid(other_and_type, symbol_and_op): # GH#35585 + other, other_type = other_and_type + symbol, op = symbol_and_op + assert not NaT == other assert not other == NaT assert NaT != other assert other != NaT - with pytest.raises(TypeError): + msg = f"'{symbol}' not supported between instances of 'NaTType' and '{other_type}'" + with pytest.raises(TypeError, match=msg): op(NaT, other) - with pytest.raises(TypeError): + msg = f"'{symbol}' not supported between instances of '{other_type}' and 'NaTType'" + with pytest.raises(TypeError, match=msg): op(other, NaT)