-
Notifications
You must be signed in to change notification settings - Fork 595
/
Copy pathconftest.py
83 lines (63 loc) · 2.4 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# coding=utf-8
#
# This file is part of Hypothesis, which may be found at
# https://github.com/HypothesisWorks/hypothesis-python
#
# Most of this work is copyright (C) 2013-2018 David R. MacIver
# ([email protected]), but it contains contributions by others. See
# CONTRIBUTING.rst for a full list of people who may hold copyright, and
# consult the git log if you need to determine who owns an individual
# contribution.
#
# This Source Code Form is subject to the terms of the Mozilla Public License,
# v. 2.0. If a copy of the MPL was not distributed with this file, You can
# obtain one at http://mozilla.org/MPL/2.0/.
#
# END HEADER
from __future__ import division, print_function, absolute_import
import gc
import sys
import time as time_module
import pytest
from tests.common import TIME_INCREMENT
from tests.common.setup import run
from hypothesis.internal.coverage import IN_COVERAGE_TESTS
run()
def pytest_configure(config):
config.addinivalue_line(
'markers',
'slow: pandas expects this marker to exist.')
@pytest.fixture(scope=u'function', autouse=True)
def gc_before_each_test():
gc.collect()
@pytest.fixture(scope=u'function', autouse=True)
def consistently_increment_time(monkeypatch):
"""Rather than rely on real system time we monkey patch time.time so that
it passes at a consistent rate between calls.
The reason for this is that when these tests run on travis, performance is
extremely variable and the VM the tests are on might go to sleep for a bit,
introducing arbitrary delays. This can cause a number of tests to fail
flakily.
Replacing time with a fake version under our control avoids this problem.
"""
frozen = [False]
current_time = [time_module.time()]
def time():
if not frozen[0]:
current_time[0] += TIME_INCREMENT
return current_time[0]
def sleep(naptime):
current_time[0] += naptime
def freeze():
frozen[0] = True
monkeypatch.setattr(time_module, 'time', time)
try:
monkeypatch.setattr(time_module, 'monotonic', time)
except AttributeError:
assert sys.version_info[0] == 2
monkeypatch.setattr(time_module, 'sleep', sleep)
monkeypatch.setattr(time_module, 'freeze', freeze, raising=False)
if not IN_COVERAGE_TESTS:
@pytest.fixture(scope=u'function', autouse=True)
def validate_lack_of_trace_function():
assert sys.gettrace() is None