forked from pymssql/pymssql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
66 lines (55 loc) · 2.23 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
from os.path import dirname
import sys
# When using tox, it can accidentally pick up a {pymssql,_mssql}.so file in the
# root directory and then get ImportError because of incompatibility in Python
# versions. By removing the root directory from the sys.path, it forces tox to
# import the library from correct place in the tox virtualenv.
if '.tox' in sys.executable:
root_dir = dirname(dirname(__file__))
sys.path.remove(root_dir)
import decimal
import os
try:
# Python 2
from ConfigParser import ConfigParser
except ImportError:
# Python 3
from configparser import ConfigParser
import pytest
import tests.helpers as th
from .helpers import cfgpath, clear_db, get_app_lock, release_app_lock
_parser = ConfigParser({
'server': 'localhost',
'username': 'sa',
'password': '',
'database': 'tempdb',
'port': '1433',
'ipaddress': '127.0.0.1',
'instance': '',
})
def pytest_addoption(parser):
parser.addoption(
"--pymssql-section",
type="string",
default=os.environ.get('PYMSSQL_TEST_CONFIG', 'DEFAULT'),
help="The name of the section to use from tests.cfg"
)
def pytest_configure(config):
_parser.read(cfgpath)
section = config.getoption('--pymssql-section')
if not _parser.has_section(section) and section != 'DEFAULT':
raise ValueError('the tests.cfg file does not have section: %s' % section)
th.config.server = os.getenv('PYMSSQL_TEST_SERVER') or _parser.get(section, 'server')
th.config.user = os.getenv('PYMSSQL_TEST_USERNAME') or _parser.get(section, 'username')
th.config.password = os.getenv('PYMSSQL_TEST_PASSWORD') or _parser.get(section, 'password')
th.config.database = os.getenv('PYMSSQL_TEST_DATABASE') or _parser.get(section, 'database')
th.config.port = os.getenv('PYMSSQL_TEST_PORT') or _parser.get(section, 'port')
th.config.ipaddress = os.getenv('PYMSSQL_TEST_IPADDRESS') or _parser.get(section, 'ipaddress')
th.config.instance = os.getenv('PYMSSQL_TEST_INSTANCE') or _parser.get(section, 'instance')
th.config.orig_decimal_prec = decimal.getcontext().prec
th.mark_slow = pytest.mark.slow
th.skip_test = pytest.skip
get_app_lock()
clear_db()
def pytest_unconfigure(config):
release_app_lock()