-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconftest.py
66 lines (48 loc) · 1.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
# -*- coding: utf-8 -*-
import os
import signal
import gevent
from gevent.pool import Group
import psutil
import pytest
import lets
def pytest_addoption(parser):
parser.addoption('--lets-timeout', default=10, metavar='SECONDS',
help='timeout for each lets test (default: 10 sec)')
def pytest_runtest_setup(item):
lets_timeout = item.config.getoption('lets_timeout')
item.timeout = gevent.Timeout.start_new(float(lets_timeout))
def pytest_runtest_teardown(item, nextitem):
try:
timeout = item.timeout
except AttributeError:
pass
else:
timeout.cancel()
children = proc().children()
for p in children:
os.kill(p.pid, signal.SIGKILL)
assert not proc().children()
group_names = ['greenlet_group', 'process_group']
@pytest.fixture(params=group_names)
def group(request):
if request.param == 'greenlet_group':
return Group()
elif request.param == 'process_group':
process_group = Group()
process_group.greenlet_class = lets.Processlet
return process_group
@pytest.fixture
def proc():
return psutil.Process(os.getpid())
@pytest.fixture
def pipe():
with lets.pipe() as (left, right):
yield (left, right)
@pytest.fixture
def count_greenlets():
# calibrate
zero = gevent.get_hub().loop.activecnt
def f():
return gevent.get_hub().loop.activecnt - zero
return f