-
Notifications
You must be signed in to change notification settings - Fork 46
/
conftest.py
40 lines (33 loc) · 1.07 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
# -*- coding: utf-8 -*-
from irc3 import testing
import pytest
import sys
import os
try:
from redis.exceptions import ConnectionError
from redis.client import StrictRedis
StrictRedis().flushdb()
except (ImportError, ConnectionError):
import re
req_redis = re.compile(r".*#[^#]*\s*require?\s*redis\s*$", re.IGNORECASE)
def pytest_runtest_setup(item):
if getattr(item, 'dtest', None):
if any(req_redis.match(e.source) for e in item.dtest.examples):
pytest.skip("No redis server is running")
dirname = os.path.dirname(__file__)
sys.path.append(os.path.join(dirname, 'examples'))
@pytest.fixture(scope="function")
def cls_event_loop(request, event_loop):
request.cls.loop = event_loop
request.cls.config['loop'] = event_loop
yield
request.cls.config.pop('loop')
@pytest.fixture(scope="function")
def irc3_bot_factory(request, event_loop):
def _bot(**config):
config['loop'] = event_loop
_b['b'] = testing.IrcBot(**config)
return _b['b']
_b = {}
yield _bot
_b['b'].SIGINT()