-
Notifications
You must be signed in to change notification settings - Fork 11
/
conftest.py
75 lines (56 loc) · 1.94 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
#!/usr/bin/env python
import os
import time
import random
import shlex
import pytest
import numpy as np
import fsleyes.render as render
from fsl.data.image import Image
from fsl.utils.tempdir import tempdir
def pytest_configure():
# When doing multiple test runs in parallel
# on the same machine, we sometimes get
# docker/xvfb-related conflicts.
if 'DISPLAY' in os.environ:
for i in range(5):
try:
import matplotlib as mpl
mpl.use('wxagg')
import matplotlib.pyplot as plt
break
except ImportError:
if i == 4:
raise
time.sleep(np.random.randint(1, 10))
# Use render to initialise an OpenGL context. Some tests
# are skipped depending on the available GL version
# (e.g. "@pytest.mark.skipif('not haveGL(3.3)')"). This
# env var can be set to ensure that GL is initialised, so
# that the haveGL expression is correctly evaluated.
if 'LOCAL_TEST_FSLEYES' in os.environ:
with tempdir():
Image(np.random.random((10, 10, 10))).save('image.nii.gz')
render.main(shlex.split('-of out.png image'))
def pytest_addoption(parser):
parser.addoption('--niters',
type=int,
action='store',
default=10,
help='Number of test iterations for imagewrapper')
parser.addoption('--seed',
type=int,
help='Seed for random number generator')
@pytest.fixture
def seed(request):
seed = request.config.getoption('--seed')
if seed is None:
seed = np.random.randint(2 ** 30)
np.random.seed(seed)
random .seed(seed)
print('Seed for random number generator: {}'.format(seed))
return seed
@pytest.fixture
def niters(request):
"""Number of test iterations."""
return request.config.getoption('--niters')