Fix flaky TestDurations test

TestDurations tests the `--durations=N` functionality which reports N
slowest tests, with durations <= 0.005s not shown by default.

The test relies on real time.sleep() (in addition to the code which uses
time.perf_counter()) which makes it flaky and inconsistent between
platforms.

Instead of trying to tweak it more, make it use fake time instead. The
way it is done is a little hacky but seems to work.
This commit is contained in:
Ran Benita
2020-04-06 23:05:15 +03:00
parent cb06bc7d6e
commit c3e6e2e8c8
2 changed files with 50 additions and 39 deletions

View File

@@ -2,8 +2,8 @@
import bdb
import os
import sys
from time import perf_counter
from time import time
from time import perf_counter # Intentionally not `import time` to avoid being
from time import time # affected by tests which monkeypatch `time` (issue #185).
from typing import Callable
from typing import Dict
from typing import List