From 86f08d924be36bb9b082d9dca2013072eee737bf Mon Sep 17 00:00:00 2001 From: James Tocknell Date: Fri, 2 Oct 2020 17:28:40 +1000 Subject: [PATCH] Fix tests failing due to pytest changes --- src/pytest_mpi/_helpers.py | 16 ++++++++++++++++ tests/test_fixtures.py | 8 +++++--- tests/test_markers.py | 10 ++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) create mode 100644 src/pytest_mpi/_helpers.py diff --git a/src/pytest_mpi/_helpers.py b/src/pytest_mpi/_helpers.py new file mode 100644 index 0000000..c63c575 --- /dev/null +++ b/src/pytest_mpi/_helpers.py @@ -0,0 +1,16 @@ +""" +Internal helpers for testing only, do not use in main code +""" +import pytest + + +def _fix_plural(**kwargs): + """ + Work around error -> errors change in pytest 6 + """ + if int(pytest.__version__[0]) >= 6: + return kwargs + if "errors" in kwargs: + errors = kwargs.pop("errors") + kwargs["error"] = errors + return kwargs diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 92819e4..a44d8e5 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -1,3 +1,5 @@ +from pytest_mpi._helpers import _fix_plural + MPI_FILE_NAME_TEST_CODE = """ import pytest @@ -56,7 +58,7 @@ def test_mpi_file_name(mpi_testdir, has_mpi4py): if has_mpi4py: result.assert_outcomes(passed=1) else: - result.assert_outcomes(error=1) + result.assert_outcomes(**_fix_plural(errors=1)) def test_mpi_tmpdir(mpi_testdir, has_mpi4py): @@ -67,7 +69,7 @@ def test_mpi_tmpdir(mpi_testdir, has_mpi4py): if has_mpi4py: result.assert_outcomes(passed=1) else: - result.assert_outcomes(error=1) + result.assert_outcomes(**_fix_plural(errors=1)) def test_mpi_tmp_path(mpi_testdir, has_mpi4py): @@ -78,4 +80,4 @@ def test_mpi_tmp_path(mpi_testdir, has_mpi4py): if has_mpi4py: result.assert_outcomes(passed=1) else: - result.assert_outcomes(error=1) + result.assert_outcomes(**_fix_plural(errors=1)) diff --git a/tests/test_markers.py b/tests/test_markers.py index d0fd94e..af3189d 100644 --- a/tests/test_markers.py +++ b/tests/test_markers.py @@ -1,3 +1,5 @@ +from pytest_mpi._helpers import _fix_plural + MPI_TEST_CODE = """ import pytest @@ -67,9 +69,9 @@ def test_mpi_with_mpi(mpi_testdir, has_mpi4py): result = mpi_testdir.runpytest("--with-mpi") if has_mpi4py: - result.assert_outcomes(passed=3, error=1, skipped=1) + result.assert_outcomes(**_fix_plural(passed=3, errors=1, skipped=1)) else: - result.assert_outcomes(passed=1, error=4) + result.assert_outcomes(**_fix_plural(passed=1, errors=4)) def test_mpi_only_mpi(mpi_testdir, has_mpi4py): @@ -78,9 +80,9 @@ def test_mpi_only_mpi(mpi_testdir, has_mpi4py): result = mpi_testdir.runpytest("--only-mpi") if has_mpi4py: - result.assert_outcomes(passed=2, error=1, skipped=2) + result.assert_outcomes(**_fix_plural(passed=2, errors=1, skipped=2)) else: - result.assert_outcomes(error=4, skipped=1) + result.assert_outcomes(**_fix_plural(errors=4, skipped=1)) def test_mpi_skip(testdir):