Repository navigation
Expand file tree
/
Copy pathconftest.py
More file actions
79 lines (61 loc) · 2.43 KB
/
Copy pathconftest.py
File metadata and controls
79 lines (61 loc) · 2.43 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
77
78
79
import sys
from mpi4py import MPI
import pytest
import numpy
import random
import tensorflow
pytest_plugins = ["tests.pytest_mpiexec_plugin"]
def pytest_configure(config):
config.option.xmlpath = "junit-{}.xml".format(MPI.COMM_WORLD.Get_rank())
def pytest_addoption(parser):
parser.addoption(
"--enable_notebook_tests",
action="store_true",
dest="enable_notebook_tests",
default=False,
help="Enable tests for Jupyter notebook examples in docs/examples. "
"These can take a long time and are disabled by default.",
)
def pytest_collection_modifyitems(config, items):
if config.getoption("--enable_notebook_tests"):
# --enable_notebook_tests given in cli: do not skip notebook tests
return
else:
enable_notebook_tests = pytest.mark.skip(
reason="needs --enable_notebook_tests option to run"
)
for item in items:
if "notebook" in item.keywords:
item.add_marker(enable_notebook_tests)
@pytest.fixture
def seeded_rng():
random.seed(0)
numpy.random.seed(0)
tensorflow.random.set_seed(0)
@pytest.fixture(scope="module", autouse=True)
def pool_size():
"""
Set the pool_size to 1 for MPI tests to avoid forking inside MPI
processes.
This replaces the old skip_non_fork fixture. We don't need to skip these
tests completely, but we need to ensure that the pool_size is set to 1 so
they don't launch any multiprocessing pools within the MPI environment.
Forking inside an MPI process can cause hangs or crashes with certain MPI
transports (e.g., libfabric EFA on AWS-based CI runners).
On windows, it seems like intel mpi and msmpi both have issues with fork,
so we need to set the pool_size to 1 there as well.
"""
# When running inside an MPI subprocess (launched by mpiexec), avoid
# forking regardless of the multiprocessing start method. On Linux the
# default start method is "fork", but fork()-after-MPI_Init is unsafe with
# many MPI transports (libfabric EFA, OpenMPI shared-memory, …).
if MPI.COMM_WORLD.Get_attr(MPI.APPNUM) is not None:
return 1
# OpenMPI has issues with fork, so we need to set the pool_size to 1
if "Open MPI" in MPI.get_vendor()[0]:
return 1
# On Windows, we need to set the pool_size to 1 for intel mpi and msmpi
elif sys.platform == "win32":
return 1
else:
return 2