fix tests fail with python 3.8

This commit is contained in:
lingsheng 2020-06-28 21:34:19 +08:00
parent 2e42cbf0d7
commit c1dd0b29a2
3 changed files with 77 additions and 39 deletions

View File

@ -1,37 +0,0 @@
From ed9daac30fb2a6c9e4f32bdbab6907012d96980d Mon Sep 17 00:00:00 2001
From: lizhenhua <lizhenhua@sina.com>
Date: Wed, 24 Jun 2020 16:34:29 +0800
Subject: [PATCH] modify test cases for python3.8
---
test_pytest_mock.py | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/test_pytest_mock.py b/test_pytest_mock.py
index d9a4faf..1fb2574 100644
--- a/test_pytest_mock.py
+++ b/test_pytest_mock.py
@@ -179,7 +179,7 @@ class TestMockerStub:
def __test_failure_message(self, mocker, **kwargs):
expected_name = kwargs.get('name') or 'mock'
- expected_message = 'Expected call: {0}()\nNot called'.format(expected_name)
+ expected_message = 'expected call not found.\nExpected: {0}()\nActual: not called.'.format(expected_name)
stub = mocker.stub(**kwargs)
with pytest.raises(AssertionError) as exc_info:
stub.assert_called_with()
@@ -560,8 +560,9 @@ def test_detailed_introspection(testdir):
""")
result = testdir.runpytest('-s')
result.stdout.fnmatch_lines([
- "*AssertionError: Expected call: mock('', bar=4)*",
- "*Actual call: mock('fo')*",
+ "*AssertionError: expected call not found.",
+ "*Expected: mock('', bar=4)",
+ "*Actual: mock('fo')",
"*pytest introspection follows:*",
'*Args:',
"*assert ('fo',) == ('',)",
--
2.23.0

View File

@ -0,0 +1,72 @@
From 91ece5ec239e7bf68e928e0377c5335ca5fc214a Mon Sep 17 00:00:00 2001
From: Daniel Hahler <git@thequod.de>
Date: Sat, 30 Mar 2019 10:58:12 +0100
Subject: [PATCH] tests: handle new output format with Python 3.8
Fixes https://github.com/pytest-dev/pytest-mock/issues/139.
---
test_pytest_mock.py | 43 +++++++++++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 14 deletions(-)
diff --git a/test_pytest_mock.py b/test_pytest_mock.py
index 1cb3889..2413593 100644
--- a/test_pytest_mock.py
+++ b/test_pytest_mock.py
@@ -12,6 +12,9 @@ pytest_plugins = 'pytester'
skip_pypy = pytest.mark.skipif(platform.python_implementation() == 'PyPy',
reason='could not make work on pypy')
+# Python 3.8 changed the output formatting (bpo-35500).
+PY38 = sys.version_info >= (3, 8)
+
@pytest.fixture
def needs_assert_rewrite(pytestconfig):
@@ -179,7 +182,11 @@ class TestMockerStub:
def __test_failure_message(self, mocker, **kwargs):
expected_name = kwargs.get('name') or 'mock'
- expected_message = 'Expected call: {0}()\nNot called'.format(expected_name)
+ if PY38:
+ msg = "expected call not found.\nExpected: {0}()\nActual: not called."
+ else:
+ msg = "Expected call: {0}()\nNot called"
+ expected_message = msg.format(expected_name)
stub = mocker.stub(**kwargs)
with pytest.raises(AssertionError) as exc_info:
stub.assert_called_with()
@@ -559,11 +566,20 @@ def test_detailed_introspection(testdir):
m.assert_called_once_with('', bar=4)
""")
result = testdir.runpytest('-s')
- result.stdout.fnmatch_lines([
- "*AssertionError: Expected call: mock('', bar=4)*",
- "*Actual call: mock('fo')*",
+ if PY38:
+ expected_lines = [
+ "*AssertionError: expected call not found.",
+ "*Expected: mock('', bar=4)",
+ "*Actual: mock('fo')",
+ ]
+ else:
+ expected_lines = [
+ "*AssertionError: Expected call: mock('', bar=4)*",
+ "*Actual call: mock('fo')*",
+ ]
+ expected_lines += [
"*pytest introspection follows:*",
- '*Args:',
+ "*Args:",
"*assert ('fo',) == ('',)",
"*At index 0 diff: 'fo' != ''*",
"*Use -v to get the full diff*",
@@ -572,7 +588,8 @@ def test_detailed_introspection(testdir):
"*Right contains more items:*",
"*{'bar': 4}*",
"*Use -v to get the full diff*",
- ])
+ ]
+ result.stdout.fnmatch_lines(expected_lines)
def test_assert_called_with_unicode_arguments(mocker):

View File

@ -1,11 +1,11 @@
Name: python-pytest-mock
Version: 1.10.0
Release: 5
Release: 6
Summary: Thin-wrapper around the mock package for easier use with py.test
License: MIT
URL: https://pypi.python.org/pypi/pytest-mock
Source0: https://files.pythonhosted.org/packages/source/p/pytest-mock/pytest-mock-%{version}.tar.gz
Patch0000: 0001-modify-test-cases-for-python3.8.patch
Patch0001: backport-tests-handle-new-output-format-with-Python-3.8.patch
BuildArch: noarch
%description
@ -75,6 +75,9 @@ PYTHONPATH="$(pwd)" py.test-%{python3_version} test_pytest_mock.py
%{python3_sitelib}/__pycache__/*
%changelog
* Sun Jun 28 2020 lingsheng <lingsheng@huawei.com> - 1.10.0-6
- Tests handle new output format with Python 3.8
* Wed Jun 24 2020 lizhenhua <lizhenhua21@huawei.com> - 1.10.0-5
- Modify test cases for python3.8