Skip to content

Commit

Permalink
Tests: Use UTC-based utcnow().date() instead of local date.today()
Browse files Browse the repository at this point in the history
`datetime.date.today()` returns the current local date. In order to
reduce test flakyness when comparing UTC-based datetimes with localtime-
based variants, `datetime.utcnow().date()` is a better choice.
  • Loading branch information
amotl committed Jul 25, 2022
1 parent a849cea commit 4cf9d00
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/crate/client/sqlalchemy/doctests/itests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ aren't set when the row is inserted as there is no default method::

The datetime and date can be set using a update statement::

>>> location.nullable_date = datetime.today()
>>> location.nullable_date = datetime.utcnow().date()
>>> location.nullable_datetime = datetime.utcnow()
>>> session.flush()

Expand Down
4 changes: 2 additions & 2 deletions src/crate/client/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import unittest
import doctest
from pprint import pprint
from datetime import datetime, date
from datetime import datetime
from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl
import time
Expand Down Expand Up @@ -213,7 +213,7 @@ class Location(Base):
__tablename__ = 'locations'
name = sa.Column(sa.String, primary_key=True)
kind = sa.Column(sa.String)
date = sa.Column(sa.Date, default=date.today)
date = sa.Column(sa.Date, default=lambda: datetime.utcnow().date())
datetime_tz = sa.Column(sa.DateTime, default=datetime.utcnow)
datetime_notz = sa.Column(sa.DateTime, default=datetime.utcnow)
nullable_datetime = sa.Column(sa.DateTime)
Expand Down

0 comments on commit 4cf9d00

Please sign in to comment.