Skip to content

Commit f9563af

Browse files
authored
Merge pull request #22 from AntoineSIMTEK/master
use skip after pytest-dev/pytest#3969 instead of xfail
2 parents 48bc0bf + 17c95e7 commit f9563af

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

README.md

+37-1
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,13 @@ MPI Tests always stop at the first error; because MPI is not fault tolerant [1].
6363
python run-tests.py --mpirun="mpirun -np 4"
6464
```
6565
66-
## Defining MPI UnitTests: MPITest decorator
66+
## Defining MPI UnitTests:
6767
6868
This feature may belong to a different package; it resides here for now before we can
6969
find a reasonable refactoring of the package.
7070
71+
### MPITest decorator
72+
7173
`MPITest` decorator allows testing with different MPI communicator sizes.
7274
7375
Example:
@@ -79,6 +81,40 @@ Example:
7981
result = myfunction(comm)
8082
assert result # or ....
8183
```
84+
85+
### MPITestFixture
86+
87+
You can combine `MPITestFixture` with other pytest fixtures or decorators, what you can't with the `MPITest` decorator.
88+
89+
Example: Parameter variation with `pytest.mark.parametrize`
90+
91+
```python
92+
from runtests.mpi import MPITestFixture
93+
import pytest
94+
95+
comm = MPITestFixture([1,2,3, 4,10], scope='function')
96+
97+
@pytest.mark.parametrize("msg",["hello","world"])
98+
def test_y(msg, comm):
99+
print(msg, comm.Get_rank())
100+
```
101+
102+
Example: Parameter variation with `pytest.fixture`
103+
```python
104+
from runtests.mpi import MPITestFixture
105+
import pytest
106+
107+
comm = MPITestFixture([1,2,3,4], scope='function')
108+
109+
@pytest.fixture(params=["hello","world"])
110+
def x(request):
111+
return request.param
112+
113+
def test_x(x, comm):
114+
print(x, comm.Get_rank())
115+
```
116+
117+
82118
## Tricks
83119

84120

runtests/mpi/tester.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,14 @@ def fixture(request):
8484
try:
8585
comm, color = create_comm(request.param)
8686

87-
# FIXME: use skip after https://github.com/pytest-dev/pytest/issues/3969 is figured out.
8887
if color != 0:
89-
request.applymarker(pytest.mark.xfail(reason="Not using communicator %d" % request.param, run=False))
88+
pytest.skip("Not using communicator %d" %(request.param))
9089
return None
9190
else:
9291
return comm
9392

9493
except WorldTooSmall:
95-
# FIXME: use skip after https://github.com/pytest-dev/pytest/issues/3969 is figured out.
96-
request.applymarker(pytest.mark.xfail(reason="World is too small", run=False))
94+
pytest.skip("Not using communicator %d" % request.param)
9795
return None
9896

9997
return fixture

0 commit comments

Comments
 (0)