-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathshared.py
47 lines (42 loc) · 1.32 KB
/
shared.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
import os
import pytest
try:
import MySQLdb
except ImportError:
MySQLdb = None
try:
import psycopg2
except ImportError:
psycopg2 = None
MYSQL_TEST_DB_CONNECTION = os.environ.get(
"MYSQL_TEST_DB_CONNECTION", "mysql://root@localhost/test_db_to_sqlite"
)
POSTGRESQL_TEST_DB_CONNECTION = os.environ.get(
"POSTGRESQL_TEST_DB_CONNECTION", "postgresql://localhost/test_db_to_sqlite"
)
def all_databases(fn):
"Decorator which parameterizes test function for mysql and postgresql"
return pytest.mark.parametrize(
"connection",
[
pytest.param(
MYSQL_TEST_DB_CONNECTION,
marks=pytest.mark.skipif(
MySQLdb is None, reason="pip install mysqlclient"
),
),
pytest.param(
POSTGRESQL_TEST_DB_CONNECTION,
marks=pytest.mark.skipif(
psycopg2 is None, reason="pip install psycopg2"
),
),
# Make sure it works with postgres:// connection strings too
pytest.param(
POSTGRESQL_TEST_DB_CONNECTION.replace("postgresql://", "postgres://"),
marks=pytest.mark.skipif(
psycopg2 is None, reason="pip install psycopg2"
),
),
],
)(fn)