Skip to content

Commit

Permalink
Drop unnecessary config
Browse files Browse the repository at this point in the history
  • Loading branch information
jwallwork23 committed Nov 23, 2024
1 parent 4920f88 commit 73fdc7a
Showing 1 changed file with 0 additions and 95 deletions.
95 changes: 0 additions & 95 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,114 +4,19 @@
**Disclaimer: some functions copied from firedrake/src/tests/conftest.py
"""

from subprocess import check_call


def parallel(item):
"""
Run a test in parallel.
**Disclaimer: copied from firedrake/src/tests/conftest.py
:arg item: the test item to run.
"""
from mpi4py import MPI

if MPI.COMM_WORLD.size > 1:
raise RuntimeError("Parallel test can't be run within parallel environment")
marker = item.get_closest_marker("parallel")
if marker is None:
raise RuntimeError("Parallel test doesn't have parallel marker")
nprocs = marker.kwargs.get("nprocs", 3)
if nprocs < 2:
raise RuntimeError("Need at least two processes to run parallel test")

# Only spew tracebacks on rank 0.
# Run xfailing tests to ensure that errors are reported to calling process.
call = [
"mpiexec",
"-n",
"1",
"python",
"-m",
"pytest",
"--runxfail",
"-s",
"-q",
"%s::%s" % (item.fspath, item.name),
]
call.extend(
[
":",
"-n",
"%d" % (nprocs - 1),
"python",
"-m",
"pytest",
"--runxfail",
"--tb=no",
"-q",
"%s::%s" % (item.fspath, item.name),
]
)
check_call(call)


def pytest_configure(config):
"""
Register an additional marker.
**Disclaimer: copied from firedrake/src/tests/conftest.py
"""
config.addinivalue_line(
"markers",
"parallel(nprocs): mark test to run in parallel on nprocs processors",
)
config.addinivalue_line(
"markers",
"slow: mark test as slow to run",
)


def pytest_runtest_setup(item):
"""
**Disclaimer: copied from firedrake/src/tests/conftest.py
"""
if item.get_closest_marker("parallel"):
from mpi4py import MPI

if MPI.COMM_WORLD.size > 1:
# Turn on source hash checking
from functools import partial

from firedrake import parameters

def _reset(check):
parameters["pyop2_options"]["check_src_hashes"] = check

# Reset to current value when test is cleaned up
item.addfinalizer(
partial(_reset, parameters["pyop2_options"]["check_src_hashes"])
)

parameters["pyop2_options"]["check_src_hashes"] = True
else:
# Blow away function arg in "master" process, to ensure
# this test isn't run on only one process.
item.obj = lambda *args, **kwargs: True


def pytest_runtest_call(item):
"""
**Disclaimer: copied from firedrake/src/tests/conftest.py
"""
from mpi4py import MPI

if item.get_closest_marker("parallel") and MPI.COMM_WORLD.size == 1:
# Spawn parallel processes to run test
parallel(item)


def pytest_runtest_teardown(item, nextitem):
"""
Clear caches after running a test
Expand Down

0 comments on commit 73fdc7a

Please sign in to comment.