forked from dials/dials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
72 lines (53 loc) · 1.97 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
#
# See https://github.com/dials/dials/wiki/pytest for documentation on how to
# write and run pytest tests, and an overview of the available features.
#
from __future__ import annotations
import multiprocessing
import os
import sys
import warnings
import pytest
# https://stackoverflow.com/a/40846742
warnings.filterwarnings("ignore", message="numpy.dtype size changed")
warnings.filterwarnings("ignore", message="numpy.ufunc size changed")
if sys.version_info[:2] == (3, 7) and sys.platform == "darwin":
multiprocessing.set_start_method("forkserver")
collect_ignore = []
def pytest_configure(config):
if not config.pluginmanager.hasplugin("dials_data"):
@pytest.fixture(scope="session")
def dials_data():
pytest.skip("This test requires the dials_data package to be installed")
globals()["dials_data"] = dials_data
@pytest.fixture(scope="session")
def dials_regression():
"""Return the absolute path to the dials_regression module as a string.
Skip the test if dials_regression is not installed."""
if "DIALS_REGRESSION" in os.environ:
return os.environ["DIALS_REGRESSION"]
try:
import dials_regression as dr
return os.path.dirname(dr.__file__)
except ImportError:
pass # dials_regression not configured
try:
import socket
reference_copy = "/dls/science/groups/scisoft/DIALS/repositories/git-reference/dials_regression"
if (
os.name == "posix"
and socket.gethostname().endswith(".diamond.ac.uk")
and os.path.exists(reference_copy)
):
return reference_copy
except ImportError:
pass # Cannot tell whether in DLS network or not
pytest.skip("dials_regression required for this test")
@pytest.fixture
def run_in_tmpdir(tmpdir):
"""Shortcut to create a temporary directory and then run the test inside
this directory."""
cwd = os.getcwd()
tmpdir.chdir()
yield tmpdir
os.chdir(cwd)