Debian Codegraph @

tests/conftest.py

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 from __future__ import annotations
2
3 import logging
4 import time
5 import timeit
6 from datetime import datetime
7
8 import freezegun
9 import pytest
10
11 import progressbar
12
13 LOG_LEVELS: dict[str, int] = {
14 '0': logging.ERROR,
15 '1': logging.WARNING,
16 '2': logging.INFO,
17 '3': logging.DEBUG,
18 }
19
20
21 def pytest_configure(config) -> None:
22 logging.basicConfig(
23 level=LOG_LEVELS.get(config.option.verbose, logging.DEBUG),
24 )
25
26
27 @pytest.fixture(autouse=True)
28 def small_interval(monkeypatch) -> None:
29 # Remove the update limit for tests by default
30 monkeypatch.setattr(
31 progressbar.ProgressBar,
32 '_MINIMUM_UPDATE_INTERVAL',
33 1e-6,
34 )
35 monkeypatch.setattr(timeit, 'default_timer', time.time)
36
37
38 @pytest.fixture(autouse=True)
39 def sleep_faster(monkeypatch):
40 # The timezone offset in seconds, add 10 seconds to make sure we don't
41 # accidentally get the wrong hour
42 offset_seconds = (datetime.now() - datetime.utcnow()).seconds + 10
43 offset_hours = int(offset_seconds / 3600)
44
45 freeze_time = freezegun.freeze_time(tz_offset=offset_hours)
46 with freeze_time as fake_time:
47 monkeypatch.setattr('time.sleep', fake_time.tick)
48 monkeypatch.setattr('timeit.default_timer', time.time)
49 yield freeze_time