Commit 9b160052 authored by Valentin Valls's avatar Valentin Valls
Browse files

Rewrite the test with pytest helpers

parent d7bc2178
Pipeline #49112 failed with stages
in 99 minutes and 45 seconds
...@@ -585,22 +585,28 @@ def test_creation_time(session): ...@@ -585,22 +585,28 @@ def test_creation_time(session):
assert "wine" not in drinks.instances assert "wine" not in drinks.instances
drinks.switch("wine") drinks.switch("wine")
# get current time
now =
# convert string to datetime obj def str2datetime(string):
creation_date = datetime.datetime.strptime( return datetime.datetime.strptime(string, "%Y-%m-%d %H:%M:%S")
drinks.creation_date, "%Y-%m-%d %H:%M:%S"
) # epsilon time bellow which time comparison is considered to be the same
assert abs(now - creation_date) < datetime.timedelta(seconds=1) # This value is pretty big to make sure the CI machine is fast enough
last_accessed = datetime.datetime.strptime( epsilon = datetime.timedelta(seconds=2).total_seconds()
drinks.last_accessed, "%Y-%m-%d %H:%M:%S"
assert abs(now - last_accessed) < datetime.timedelta(seconds=2)
# creation and last access was done now
now =
creation_date = str2datetime(drinks.creation_date)
assert creation_date.timestamp() == pytest.approx(now.timestamp(), abs=epsilon)
last_accessed = str2datetime(drinks.last_accessed)
assert last_accessed.timestamp() == pytest.approx(now.timestamp(), abs=epsilon)
# a later access update the last access time
gevent.sleep(1) gevent.sleep(1)
drinks.creation_date # access it => will change 'last_accessed' drinks.creation_date # access it => will change 'last_accessed'
assert drinks.last_accessed != str(drinks.creation_date) now =
last_accessed2 = str2datetime(drinks.last_accessed)
assert last_accessed != last_accessed2, "last_accessed was not updated"
assert last_accessed2.timestamp() == pytest.approx(now.timestamp(), abs=epsilon)
def test_from_dict_ok(session): def test_from_dict_ok(session):
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment