-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
66 lines (51 loc) · 1.54 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
import os
import sys
from unittest import mock
import pytest
INDY_FOUND = False
INDY_STUB = None
POSTGRES_URL = None
def pytest_sessionstart(session):
global INDY_FOUND, INDY_STUB, POSTGRES_URL
# detect indy module
try:
from indy.libindy import _cdll
_cdll()
INDY_FOUND = True
except ImportError:
print("Skipping Indy-specific tests: python3-indy module not installed.")
except OSError:
print(
"Skipping Indy-specific tests: libindy shared library could not be loaded."
)
if not INDY_FOUND:
modules = {}
package_name = "indy"
modules[package_name] = mock.MagicMock()
for mod in [
"anoncreds",
"blob_storage",
"crypto",
"did",
"error",
"pool",
"ledger",
"non_secrets",
"pairwise",
"wallet",
]:
submod = f"{package_name}.{mod}"
modules[submod] = mock.MagicMock()
INDY_STUB = mock.patch.dict(sys.modules, modules)
INDY_STUB.start()
POSTGRES_URL = os.getenv("POSTGRES_URL")
def pytest_sessionfinish(session):
global INDY_STUB
if INDY_STUB:
INDY_STUB.stop()
INDY_STUB = None
def pytest_runtest_setup(item: pytest.Item):
if tuple(item.iter_markers(name="indy")) and not INDY_FOUND:
pytest.skip("test requires Indy support")
if tuple(item.iter_markers(name="postgres")) and not POSTGRES_URL:
pytest.skip("test requires Postgres support")