Skip to content

Commit

Permalink
Portability Pytest 8. Added two tests to check complex assertions
Browse files Browse the repository at this point in the history
closes #12
  • Loading branch information
BerengerBerthoul committed Dec 6, 2024
1 parent 7ef334e commit 7855c4b
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 1 deletion.
11 changes: 10 additions & 1 deletion pytest_parallel/plugin.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import sys
import subprocess
import tempfile
import pytest
from pathlib import Path
import argparse
import resource
import pytest
from _pytest.terminal import TerminalReporter

# --------------------------------------------------------------------------
def pytest_addoption(parser):
Expand Down Expand Up @@ -164,9 +166,16 @@ def pytest_configure(config):

# only report to terminal if master process
if not enable_terminal_reporter:
# unregister the stdout terminal reporter
terminal_reporter = config.pluginmanager.getplugin('terminalreporter')
config.pluginmanager.unregister(terminal_reporter)

# Pytest relies on having a terminal reporter to decide on how to create error messages, see #12
# Hence, register a terminal reporter that outputs to /dev/null
null_file = open(os.devnull,'w')
terminal_reporter = TerminalReporter(config, null_file)
config.pluginmanager.register(terminal_reporter, "terminalreporter")


# --------------------------------------------------------------------------
@pytest.fixture
Expand Down
54 changes: 54 additions & 0 deletions test/pytest_parallel_refs/terminal_fail_complex_assert_two_procs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[=]+ test session starts [=]+
platform [^\n]*
cachedir: [^\n]*
?(?:metadata: [^\n]*)?
rootdir: [^\n]*
?(?:configfile: [^\n]*)?
?(?:plugins: [^\n]*)?
collecting ... [\s]*collected 1 item[\s]*
?(?:Submitting tests to SLURM...)?
?(?:SLURM job [^\n]* has been submitted)?

[^\n]*test_fail_complex_assert_two_procs.py::test_fail_with_complex_assert_reporting\[2\] FAILED

[=]+ FAILURES [=]+
[_]+ test_fail_with_complex_assert_reporting\[2\] [_]+

[-]+ On rank 0 of 2 [-]+
comm = <mpi4py.MPI.Intracomm object at [^\n]*>

@pytest_parallel.mark.parallel\(2\)
def test_fail_with_complex_assert_reporting\(comm\):
if comm.Get_rank\(\) == 0:
> assert 1 == 0
E assert 1 == 0

[^\n]*test_fail_complex_assert_two_procs.py:7: AssertionError

[-]+ On rank 1 of 2 [-]+
comm = <mpi4py.MPI.Intracomm object at [^\n]*>

@pytest_parallel.mark.parallel\(2\)
def test_fail_with_complex_assert_reporting\(comm\):
if comm.Get_rank\(\) == 0:
assert 1 == 0
if comm.Get_rank\(\) == 1:
> assert \[0,1,2\] == \[0,1,3\]
E assert \[0, 1, 2\] == \[0, 1, 3\]
E
E At index 2 diff: 2 != 3
E
E Full diff:
E \[
E 0,
E 1,
E - 3,
E \? \^
E \+ 2,
E \? \^
E \]

[^\n]*test_fail_complex_assert_two_procs.py:9: AssertionError
[=]+ short test summary info [=]+
FAILED [^\n]*test_fail_complex_assert_two_procs.py::test_fail_with_complex_assert_reporting\[2\][^\n]*
[=]+ 1 failed in [^\n]*s [=]+
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pytest_parallel


@pytest_parallel.mark.parallel(2)
def test_fail_with_complex_assert_reporting(comm):
if comm.Get_rank() == 0:
assert 1 == 0
if comm.Get_rank() == 1:
assert [0,1,2] == [0,1,3]

0 comments on commit 7855c4b

Please sign in to comment.