File: test_markers.py

package info (click to toggle)
pytest-mpi 0.6-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 404 kB
  • sloc: python: 2,070; makefile: 28; sh: 22
file content (120 lines) | stat: -rw-r--r-- 2,615 bytes parent folder | download | duplicates (2)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from pytest_mpi._helpers import _fix_plural

MPI_TEST_CODE = """
    import pytest

    @pytest.mark.mpi
    def test_size():
        from mpi4py import MPI
        comm = MPI.COMM_WORLD

        assert comm.size > 0

    @pytest.mark.mpi(min_size=2)
    def test_size_min_2():
        from mpi4py import MPI
        comm = MPI.COMM_WORLD

        assert comm.size >= 2

    @pytest.mark.mpi(min_size=4)
    def test_size_min_4():
        from mpi4py import MPI
        comm = MPI.COMM_WORLD

        assert comm.size >= 4

    @pytest.mark.mpi(2)
    def test_size_fail_pos():
        from mpi4py import MPI
        comm = MPI.COMM_WORLD

        assert comm.size > 0

    def test_no_mpi():
        assert True
"""
MPI_SKIP_TEST_CODE = """
    import pytest

    @pytest.mark.mpi_skip
    def test_skip():
        assert True
"""
MPI_XFAIL_TEST_CODE = """
    import pytest

    @pytest.mark.mpi_xfail
    def test_xfail():
        try:
            from mpi4py import MPI
            comm = MPI.COMM_WORLD
            assert comm.size < 2
        except ImportError:
            assert True
"""


def test_mpi(testdir):
    testdir.makepyfile(MPI_TEST_CODE)

    result = testdir.runpytest()

    result.assert_outcomes(skipped=4, passed=1)


def test_mpi_with_mpi(mpi_testdir, has_mpi4py):
    mpi_testdir.makepyfile(MPI_TEST_CODE)

    result = mpi_testdir.runpytest("--with-mpi")

    if has_mpi4py:
        result.assert_outcomes(**_fix_plural(passed=3, errors=1, skipped=1))
    else:
        result.assert_outcomes(**_fix_plural(passed=1, errors=4))


def test_mpi_only_mpi(mpi_testdir, has_mpi4py):
    mpi_testdir.makepyfile(MPI_TEST_CODE)

    result = mpi_testdir.runpytest("--only-mpi")

    if has_mpi4py:
        result.assert_outcomes(**_fix_plural(passed=2, errors=1, skipped=2))
    else:
        result.assert_outcomes(**_fix_plural(errors=4, skipped=1))


def test_mpi_skip(testdir):
    testdir.makepyfile(MPI_SKIP_TEST_CODE)

    result = testdir.runpytest()

    result.assert_outcomes(passed=1)


def test_mpi_skip_under_mpi(mpi_testdir):
    mpi_testdir.makepyfile(MPI_SKIP_TEST_CODE)

    result = mpi_testdir.runpytest("--with-mpi")

    result.assert_outcomes(skipped=1)


def test_mpi_xfail(testdir):
    testdir.makepyfile(MPI_XFAIL_TEST_CODE)

    result = testdir.runpytest()

    result.assert_outcomes(passed=1)


def test_mpi_xfail_under_mpi(mpi_testdir, has_mpi4py):
    mpi_testdir.makepyfile(MPI_XFAIL_TEST_CODE)

    result = mpi_testdir.runpytest("--with-mpi")

    if has_mpi4py:
        result.assert_outcomes(xfailed=1)
    else:
        result.assert_outcomes(xpassed=1)