Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Python 3.8 #140

Merged
merged 3 commits into from
Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: python
dist: xenial

install:
- pip install -U pip
Expand Down Expand Up @@ -27,8 +28,8 @@ jobs:
env: TOXENV=py36
- python: '3.7'
env: TOXENV=py37
sudo: required
dist: xenial
- python: '3.8-dev'
env: TOXENV=py38
- python: '3.6'
env: TOXENV=linting
- python: '3.6'
Expand Down
47 changes: 31 additions & 16 deletions test_pytest_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
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):
Expand Down Expand Up @@ -185,7 +188,7 @@ def test_call(self, mocker):

def test_repr_with_no_name(self, mocker):
stub = mocker.stub()
assert not "name" in repr(stub)
assert "name" not in repr(stub)

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

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()
Expand Down Expand Up @@ -585,22 +592,30 @@ def test(mocker):
"""
)
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines(
[
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')*",
"*pytest introspection follows:*",
"*Args:",
"*assert ('fo',) == ('',)",
"*At index 0 diff: 'fo' != ''*",
"*Use -v to get the full diff*",
"*Kwargs:*",
"*assert {} == {'bar': 4}*",
"*Right contains more items:*",
"*{'bar': 4}*",
"*Use -v to get the full diff*",
]
)
expected_lines += [
"*pytest introspection follows:*",
"*Args:",
"*assert ('fo',) == ('',)",
"*At index 0 diff: 'fo' != ''*",
"*Use -v to get the full diff*",
"*Kwargs:*",
"*assert {} == {'bar': 4}*",
"*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):
Expand All @@ -613,7 +628,7 @@ def test_assert_called_with_unicode_arguments(mocker):


def test_plain_stopall(testdir):
"""Calling patch.stopall() in a test would cause an error during unconfigure (#137)"""
"""patch.stopall() in a test should not cause an error during unconfigure (#137)"""
testdir.makepyfile(
"""
import random
Expand Down
3 changes: 3 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ commands = pre-commit run --all-files --show-diff-on-failure

[pytest]
addopts = -ra

[flake8]
max-line-length = 88