/
conftest.py
87 lines (69 loc) · 2.61 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
## vi: tabstop=4 shiftwidth=4 softtabstop=4 expandtab
## ---------------------------------------------------------------------
##
## Copyright (C) 2019 by the adcc authors
##
## This file is part of adcc.
##
## adcc is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published
## by the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## adcc is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with adcc. If not, see <http://www.gnu.org/licenses/>.
##
## ---------------------------------------------------------------------
import os
import pytest
from .testdata.cache import TestdataCache
def update_testdata(session):
import subprocess
testdata_dir = os.path.join(os.path.dirname(__file__), "testdata")
cmd = [testdata_dir + "/0_download_testdata.sh"]
if session.config.option.mode == "full":
cmd.append("--full")
subprocess.check_call(cmd)
def setup_continuous_integration(session):
"""
If we are in a continuous integration environment,
be more moderate with the thread setup.
"""
import adcc
print("Detected continuous integration session")
adcc.set_n_threads(2)
#
# Pytest Hooks
#
def pytest_addoption(parser):
parser.addoption(
"--mode", default="fast", choices=["fast", "full"],
help="Mode for testing (fast or full)"
)
parser.addoption(
"--skip-update", default=False, action="store_true",
help="Skip updating testdata"
)
def pytest_collection_modifyitems(config, items):
slowcases = ["h2o_def2tzvp", "h2o_ccpvdz", "cn_ccpvdz",
"h2s_6311g", "ch2nh2_ccpvdz", "r2methyloxirane_ccpvdz",
"formaldehyde_ccpvdz"]
if config.getoption("mode") == "fast":
skip_slow = pytest.mark.skip(reason="need '--mode full' option to run.")
for item in items:
if any(name in kw for kw in item.keywords for name in slowcases):
item.add_marker(skip_slow)
def pytest_collection(session):
if not session.config.option.skip_update:
update_testdata(session)
if session.config.option.mode == "full":
TestdataCache.enable_mode_full()
def pytest_runtestloop(session):
if os.environ.get("CI", "false") == "true":
setup_continuous_integration(session)