-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathconftest.py
More file actions
76 lines (54 loc) · 2.42 KB
/
Copy pathconftest.py
File metadata and controls
76 lines (54 loc) · 2.42 KB
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
67
68
69
70
71
72
73
74
75
76
import warnings
import pytest
def _ensure_ssl_cert_file():
"""Point OpenSSL at certifi's CA bundle for the whole test session.
chimerax.core.__main__.init() does this at app startup, but tests run the
bare interpreter (make pytest-both-exes / pytest-app / pytest-wheel) and make
HTTPS requests without ever calling init(). The build also exports a
SSL_CERT_FILE (mk/config.make) that only resolves inside the installed app,
and python-build-standalone's bundled OpenSSL has no usable default CA path,
so without this OpenSSL loads zero CAs and every certificate verification
fails. Assign unconditionally, exactly as init() does, so we override that
stale export rather than deferring to it.
"""
import os
try:
import certifi
except ImportError:
return
os.environ["SSL_CERT_FILE"] = certifi.where()
# Run at conftest import time, before any test is collected or run, so every
# invocation of the test harness has working HTTPS regardless of entry point.
_ensure_ssl_cert_file()
@pytest.fixture(scope="function")
def ensure_chimerax_initialized():
_ensure_chimerax_initialized()
# You can import this hidden one if you need to run code that needs ChimeraX initialized before
# the tests even run, as in amber_info, which tries to access chimerax.app_bin_dir when you import
# it.
def _ensure_chimerax_initialized():
import chimerax
if not getattr(chimerax, "app_bin_dir", None):
import chimerax.core.__main__
chimerax.core.__main__.init(["dummy", "--nogui", "--safemode", "--exit"])
_test_session = None
def get_test_session():
global _test_session
if _test_session is None:
from chimerax.core import get_minimal_test_session
with warnings.catch_warnings(action="ignore"):
_test_session = get_minimal_test_session()
return _test_session
@pytest.fixture(scope="function")
def test_production_session():
session = get_test_session()
yield session
session.reset()
def pytest_configure(config):
markexpr = config.getoption("markexpr")
if "not wheel" in markexpr:
# Initialize the test session before tests are even collected, because
# pytest's usual schtick of importing modules BEFORE the tests are collected
# totally breaks code that modifies __all__s at runtime. We need ChimeraX to
# always be the first thing that runs in any tool.
_ = get_test_session()