forked from pediapress/mwlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
53 lines (39 loc) · 1.29 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
import os, sys
xnet = os.environ.get("XNET", "") # eXclude NETwork tests
try:
xnet = int(xnet)
except ValueError:
pass
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
def pytest_funcarg__alarm(request):
import signal, time, math
def sighandler(signum, frame):
__tracebackhide__ = True
raise RuntimeError("timeout after %s seconds" % (time.time() - stime))
def cleanup():
if hasattr(signal, "setitimer"):
signal.setitimer(signal.ITIMER_REAL, 0)
else:
signal.alarm(0)
signal.signal(signal.SIGALRM, old_handler)
def alarm(secs):
if hasattr(signal, "setitimer"):
signal.setitimer(signal.ITIMER_REAL, secs)
else:
signal.alarm(math.ceil(secs))
request.addfinalizer(cleanup)
stime = time.time()
old_handler = signal.signal(signal.SIGALRM, sighandler)
return alarm
def pytest_configure(config):
kw = config.getvalue("keyword")
if "xnet" in kw:
return
if xnet:
print "conftest.py: disabling tests marked with keyword xnet."
print "conftest.py: set environment variable XNET=0 to enable them."
if kw:
kw = kw+" -xnet"
else:
kw = "-xnet"
config.option.keyword = kw