Skip to content

Commit b2b1aae

Browse files
authored
TST: Allow test_dti_constructor_with_non_nano_now_today to be flaky (pandas-dev#57535)
* TST: Allow test_dti_constructor_with_non_nano_now_today to be flaky * Add GH reference * Add reason
1 parent 7a5a5c7 commit b2b1aae

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

pandas/tests/indexes/datetimes/test_constructors.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -1031,23 +1031,28 @@ def test_dti_constructor_with_non_nano_dtype(self, tz):
10311031
result2 = DatetimeIndex(np.array(vals, dtype=object), dtype=dtype)
10321032
tm.assert_index_equal(result2, expected)
10331033

1034-
def test_dti_constructor_with_non_nano_now_today(self):
1034+
def test_dti_constructor_with_non_nano_now_today(self, request):
10351035
# GH#55756
10361036
now = Timestamp.now()
10371037
today = Timestamp.today()
10381038
result = DatetimeIndex(["now", "today"], dtype="M8[s]")
10391039
assert result.dtype == "M8[s]"
10401040

1041+
diff0 = result[0] - now.as_unit("s")
1042+
diff1 = result[1] - today.as_unit("s")
1043+
assert diff1 >= pd.Timedelta(0), f"The difference is {diff0}"
1044+
assert diff0 >= pd.Timedelta(0), f"The difference is {diff0}"
1045+
10411046
# result may not exactly match [now, today] so we'll test it up to a tolerance.
10421047
# (it *may* match exactly due to rounding)
1048+
# GH 57535
1049+
request.applymarker(
1050+
pytest.mark.xfail(
1051+
reason="result may not exactly match [now, today]", strict=False
1052+
)
1053+
)
10431054
tolerance = pd.Timedelta(seconds=1)
1044-
1045-
diff0 = result[0] - now.as_unit("s")
1046-
assert diff0 >= pd.Timedelta(0), f"The difference is {diff0}"
10471055
assert diff0 < tolerance, f"The difference is {diff0}"
1048-
1049-
diff1 = result[1] - today.as_unit("s")
1050-
assert diff1 >= pd.Timedelta(0), f"The difference is {diff0}"
10511056
assert diff1 < tolerance, f"The difference is {diff0}"
10521057

10531058
def test_dti_constructor_object_float_matches_float_dtype(self):

0 commit comments

Comments
 (0)