1 Star 0 Fork 18

ultra_planet/python-pytest-mock

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
backport-tests-handle-new-output-format-with-Python-3.8.patch 2.59 KB
一键复制 编辑 原始数据 按行查看 历史
lingsheng 提交于 2020-06-28 21:34 . fix tests fail with python 3.8
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):
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ultra_planet/python-pytest-mock.git
git@gitee.com:ultra_planet/python-pytest-mock.git
ultra_planet
python-pytest-mock
python-pytest-mock
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385