I'm using freeze-time
to run my python unittest
Test cases.
A dummy test case:
@freeze_time('2020-01-01')
def test_something(self):
expected_output = {'time': '2020-01-01'}
output = call_tested_code()
self.assertEqual(expected_output, output)
Main code / Code that is being tested:
GET_CURRENT_TIME = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
def call_tested_code():
return {'time': GET_CURRENT_TIME}
This is failing, as the output is giving current_date instead of frozen date. It was working when the GET_CURRENT_TIME
was a lambda, but that results in different timestamps for my code, which I don't want.
Feel free to comment if any additional Information is required. Thanks
Aucun commentaire:
Enregistrer un commentaire