Commit 41b43b9b authored by Matias Guijarro's avatar Matias Guijarro
Browse files

Merge branch 'fix-test-settings-dangling' into 'master'

CI: Fix dangling test in settings

Closes #2561

See merge request !3809
parents 41a9b157 9b160052
Pipeline #49138 failed with stages
in 50 minutes and 48 seconds
......@@ -579,30 +579,34 @@ def test_wardrobe_get_current_instance(session):
def test_creation_time(session):
drinks = settings.ParametersWardrobe("drinks")
# an empty Wardrobe has only creation/access info
assert len(drinks.to_dict(export_properties=True)) == 3
assert "wine" not in drinks.instances
# get current time
now =
# convert string to datetime obj
creation_date = datetime.datetime.strptime(
drinks.creation_date, "%Y-%m-%d %H:%M:%S"
assert abs(now - creation_date) < datetime.timedelta(seconds=60)
last_accessed = datetime.datetime.strptime(
drinks.last_accessed, "%Y-%m-%d %H:%M:%S"
assert abs(now - last_accessed) < datetime.timedelta(seconds=60)
# an empty Wardrobe has only creation/access info
food = settings.ParametersWardrobe("food")
assert len(food.to_dict(export_properties=True)) == 3
def str2datetime(string):
return datetime.datetime.strptime(string, "%Y-%m-%d %H:%M:%S")
# epsilon time bellow which time comparison is considered to be the same
# This value is pretty big to make sure the CI machine is fast enough
epsilon = datetime.timedelta(seconds=2).total_seconds()
# 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
food.creation_date # access it => will change 'last_accessed'
assert food.creation_date == str(creation_date)
assert food.last_accessed != str(creation_date)
drinks.creation_date # access it => will change 'last_accessed'
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):
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