Skip to content

Commit

Permalink
chore(tests): fix flaky test on windows (#959)
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed Apr 28, 2024
1 parent 7778b73 commit da53c42
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/testing/_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ def assert_similar_time(dt1: datetime, dt2: datetime, threshold: float = 0.5) ->


def assert_time_like_now(dt: datetime, threshold: int = 10) -> None:
delta = datetime.now(timezone.utc) - dt
assert delta.days == 0, delta
assert delta.total_seconds() < threshold, delta
now = datetime.now(timezone.utc)

delta = now - dt
if delta.days < 0:
# for some reason the delta can be negative on windows
delta = dt - now

assert delta.days == 0, f'delta={delta} dt={dt} now={now}'
assert delta.total_seconds() < threshold, f'delta={delta} dt={dt} now={now}'

0 comments on commit da53c42

Please sign in to comment.