diff --git a/pandas/tests/indexes/datetimes/test_constructors.py b/pandas/tests/indexes/datetimes/test_constructors.py index 0756d490cd4fa..009723fc42360 100644 --- a/pandas/tests/indexes/datetimes/test_constructors.py +++ b/pandas/tests/indexes/datetimes/test_constructors.py @@ -1031,23 +1031,28 @@ def test_dti_constructor_with_non_nano_dtype(self, tz): result2 = DatetimeIndex(np.array(vals, dtype=object), dtype=dtype) tm.assert_index_equal(result2, expected) - def test_dti_constructor_with_non_nano_now_today(self): + def test_dti_constructor_with_non_nano_now_today(self, request): # GH#55756 now = Timestamp.now() today = Timestamp.today() result = DatetimeIndex(["now", "today"], dtype="M8[s]") assert result.dtype == "M8[s]" + diff0 = result[0] - now.as_unit("s") + diff1 = result[1] - today.as_unit("s") + assert diff1 >= pd.Timedelta(0), f"The difference is {diff0}" + assert diff0 >= pd.Timedelta(0), f"The difference is {diff0}" + # result may not exactly match [now, today] so we'll test it up to a tolerance. # (it *may* match exactly due to rounding) + # GH 57535 + request.applymarker( + pytest.mark.xfail( + reason="result may not exactly match [now, today]", strict=False + ) + ) tolerance = pd.Timedelta(seconds=1) - - diff0 = result[0] - now.as_unit("s") - assert diff0 >= pd.Timedelta(0), f"The difference is {diff0}" assert diff0 < tolerance, f"The difference is {diff0}" - - diff1 = result[1] - today.as_unit("s") - assert diff1 >= pd.Timedelta(0), f"The difference is {diff0}" assert diff1 < tolerance, f"The difference is {diff0}" def test_dti_constructor_object_float_matches_float_dtype(self):