Merge master into features

Several conflicts, mostly due to 2c402f4bd.

Conflicts:
	.pre-commit-config.yaml
	src/_pytest/outcomes.py
	src/_pytest/python_api.py
	tox.ini
This commit is contained in:
Daniel Hahler
2019-08-02 16:20:21 +02:00
66 changed files with 626 additions and 235 deletions

View File

@@ -104,21 +104,15 @@ class TestMockDecoration:
values = getfuncargnames(f)
assert values == ("x",)
@pytest.mark.xfail(
strict=False, reason="getfuncargnames breaks if mock is imported"
)
def test_wrapped_getfuncargnames_patching(self):
def test_getfuncargnames_patching(self):
from _pytest.compat import getfuncargnames
from unittest.mock import patch
def wrap(f):
def func():
class T:
def original(self, x, y, z):
pass
func.__wrapped__ = f
func.patchings = ["qwe"]
return func
@wrap
@patch.object(T, "original")
def f(x, y, z):
pass
@@ -126,7 +120,6 @@ class TestMockDecoration:
assert values == ("y", "z")
def test_unittest_mock(self, testdir):
pytest.importorskip("unittest.mock")
testdir.makepyfile(
"""
import unittest.mock
@@ -142,7 +135,6 @@ class TestMockDecoration:
reprec.assertoutcome(passed=1)
def test_unittest_mock_and_fixture(self, testdir):
pytest.importorskip("unittest.mock")
testdir.makepyfile(
"""
import os.path
@@ -164,7 +156,6 @@ class TestMockDecoration:
reprec.assertoutcome(passed=1)
def test_unittest_mock_and_pypi_mock(self, testdir):
pytest.importorskip("unittest.mock")
pytest.importorskip("mock", "1.0.1")
testdir.makepyfile(
"""
@@ -187,6 +178,34 @@ class TestMockDecoration:
reprec = testdir.inline_run()
reprec.assertoutcome(passed=2)
def test_mock_sentinel_check_against_numpy_like(self, testdir):
"""Ensure our function that detects mock arguments compares against sentinels using
identity to circumvent objects which can't be compared with equality against others
in a truth context, like with numpy arrays (#5606).
"""
testdir.makepyfile(
dummy="""
class NumpyLike:
def __init__(self, value):
self.value = value
def __eq__(self, other):
raise ValueError("like numpy, cannot compare against others for truth")
FOO = NumpyLike(10)
"""
)
testdir.makepyfile(
"""
from unittest.mock import patch
import dummy
class Test(object):
@patch("dummy.FOO", new=dummy.NumpyLike(50))
def test_hello(self):
assert dummy.FOO.value == 50
"""
)
reprec = testdir.inline_run()
reprec.assertoutcome(passed=1)
def test_mock(self, testdir):
pytest.importorskip("mock", "1.0.1")
testdir.makepyfile(