diff --git a/.travis.yml b/.travis.yml index 47eccd2..f1dc503 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: python +dist: xenial install: - pip install -U pip @@ -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' diff --git a/test_pytest_mock.py b/test_pytest_mock.py index 1cb3889..9c29651 100644 --- a/test_pytest_mock.py +++ b/test_pytest_mock.py @@ -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): @@ -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" @@ -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() @@ -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): @@ -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 diff --git a/tox.ini b/tox.ini index e0efa9c..427b25f 100644 --- a/tox.ini +++ b/tox.ini @@ -21,3 +21,6 @@ commands = pre-commit run --all-files --show-diff-on-failure [pytest] addopts = -ra + +[flake8] +max-line-length = 88