Sunday, 18 April 2021

How to pause pytest timer?

I have a parametrized (py)test that cleans up some table in the DB before running the logic:

@pytest.mark.parametrize('limit', [1, 1000, 5000000])
def test_calc(limit):
    # clean test table in database !!!
    assert calc(limit) == None

At the end of the tests I get:

=========== 3 passed in 357.65s (0:05:57) ===========

The problem is that about 2-3 minutes of that is the table cleanup.

How can I pause the timer before the cleanup and continue the timer after the cleanup finished ?

Like in Golang's testing library - T.StopTimer() & T.StartTime()

I searched all over google, and the closest thing I stumbled upon was freezegun.
I tried it out but couldn't get rid of the cleanup time, maybe I was using it somehow wrong :/
As far I understood it manipulates the datetime object but not pytest's timer (mechanism) :(



from How to pause pytest timer?

No comments:

Post a Comment