Benjamin Bossan commited on
Commit
5757778
1 Parent(s): 01ae0bb

Don't use naive datetime objects

Browse files
Files changed (1) hide show
  1. tests/test_app.py +3 -1
tests/test_app.py CHANGED
@@ -8,8 +8,10 @@ from fastapi.testclient import TestClient
8
 
9
  def is_roughly_now(datetime_str):
10
  """Check if a datetime string is roughly from now"""
11
- now = dt.datetime.utcnow()
12
  datetime = dt.datetime.fromisoformat(datetime_str)
 
 
13
  return (now - datetime).total_seconds() < 3
14
 
15
 
 
8
 
9
  def is_roughly_now(datetime_str):
10
  """Check if a datetime string is roughly from now"""
11
+ now = dt.datetime.now(dt.timezone.utc)
12
  datetime = dt.datetime.fromisoformat(datetime_str)
13
+ # set timezone, otherwise cannot subtract
14
+ datetime = datetime.replace(tzinfo=dt.timezone.utc)
15
  return (now - datetime).total_seconds() < 3
16
 
17