Go To The Beggining Of Time

Published on Oct. 19, 2022 | Tags: python pytest datetime TIL

Yesterday, I was trying to create some kind of expired token and I figured I'd put the earliest date I could to ensure it was expired later on.
Then, at some other point, the function time.time() is called and, of course it returned 0.0! I did not realise at first but was a funny encounter.


import pytest
import time

@pytest.mark.freeze_time("1970-01-01")
def test_the_beginning_of_time():
assert time.time() == 0.0

(You'll need pytest and pytest-freezegun to run this snippet).


Ferran Jovell