Skip to content

Commit c389395

Browse files
authored
Merge pull request #140 from nicoddemus/fix-py38
Fix Python 3.8
2 parents 540c17b + 4f33eb5 commit c389395

File tree

3 files changed

+37
-18
lines changed

3 files changed

+37
-18
lines changed

.travis.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
language: python
2+
dist: xenial
23

34
install:
45
- pip install -U pip
@@ -27,8 +28,8 @@ jobs:
2728
env: TOXENV=py36
2829
- python: '3.7'
2930
env: TOXENV=py37
30-
sudo: required
31-
dist: xenial
31+
- python: '3.8-dev'
32+
env: TOXENV=py38
3233
- python: '3.6'
3334
env: TOXENV=linting
3435
- python: '3.6'

test_pytest_mock.py

+31-16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
platform.python_implementation() == "PyPy", reason="could not make work on pypy"
1414
)
1515

16+
# Python 3.8 changed the output formatting (bpo-35500).
17+
PY38 = sys.version_info >= (3, 8)
18+
1619

1720
@pytest.fixture
1821
def needs_assert_rewrite(pytestconfig):
@@ -185,7 +188,7 @@ def test_call(self, mocker):
185188

186189
def test_repr_with_no_name(self, mocker):
187190
stub = mocker.stub()
188-
assert not "name" in repr(stub)
191+
assert "name" not in repr(stub)
189192

190193
def test_repr_with_name(self, mocker):
191194
test_name = "funny walk"
@@ -194,7 +197,11 @@ def test_repr_with_name(self, mocker):
194197

195198
def __test_failure_message(self, mocker, **kwargs):
196199
expected_name = kwargs.get("name") or "mock"
197-
expected_message = "Expected call: {0}()\nNot called".format(expected_name)
200+
if PY38:
201+
msg = "expected call not found.\nExpected: {0}()\nActual: not called."
202+
else:
203+
msg = "Expected call: {0}()\nNot called"
204+
expected_message = msg.format(expected_name)
198205
stub = mocker.stub(**kwargs)
199206
with pytest.raises(AssertionError) as exc_info:
200207
stub.assert_called_with()
@@ -585,22 +592,30 @@ def test(mocker):
585592
"""
586593
)
587594
result = testdir.runpytest("-s")
588-
result.stdout.fnmatch_lines(
589-
[
595+
if PY38:
596+
expected_lines = [
597+
"*AssertionError: expected call not found.",
598+
"*Expected: mock('', bar=4)",
599+
"*Actual: mock('fo')",
600+
]
601+
else:
602+
expected_lines = [
590603
"*AssertionError: Expected call: mock('', bar=4)*",
591604
"*Actual call: mock('fo')*",
592-
"*pytest introspection follows:*",
593-
"*Args:",
594-
"*assert ('fo',) == ('',)",
595-
"*At index 0 diff: 'fo' != ''*",
596-
"*Use -v to get the full diff*",
597-
"*Kwargs:*",
598-
"*assert {} == {'bar': 4}*",
599-
"*Right contains more items:*",
600-
"*{'bar': 4}*",
601-
"*Use -v to get the full diff*",
602605
]
603-
)
606+
expected_lines += [
607+
"*pytest introspection follows:*",
608+
"*Args:",
609+
"*assert ('fo',) == ('',)",
610+
"*At index 0 diff: 'fo' != ''*",
611+
"*Use -v to get the full diff*",
612+
"*Kwargs:*",
613+
"*assert {} == {'bar': 4}*",
614+
"*Right contains more items:*",
615+
"*{'bar': 4}*",
616+
"*Use -v to get the full diff*",
617+
]
618+
result.stdout.fnmatch_lines(expected_lines)
604619

605620

606621
def test_assert_called_with_unicode_arguments(mocker):
@@ -613,7 +628,7 @@ def test_assert_called_with_unicode_arguments(mocker):
613628

614629

615630
def test_plain_stopall(testdir):
616-
"""Calling patch.stopall() in a test would cause an error during unconfigure (#137)"""
631+
"""patch.stopall() in a test should not cause an error during unconfigure (#137)"""
617632
testdir.makepyfile(
618633
"""
619634
import random

tox.ini

+3
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ commands = pre-commit run --all-files --show-diff-on-failure
2121

2222
[pytest]
2323
addopts = -ra
24+
25+
[flake8]
26+
max-line-length = 88

0 commit comments

Comments
 (0)