ignore magic callables with no sane code in factory/setup discovery
This commit is contained in:
parent
1446b4b4e6
commit
0cca20bef9
|
@ -44,6 +44,9 @@ Changes between 2.2.4 and 2.3.0.dev
|
||||||
|
|
||||||
- fix issue 178: xml binary escapes are now wrapped in py.xml.raw
|
- fix issue 178: xml binary escapes are now wrapped in py.xml.raw
|
||||||
|
|
||||||
|
- factory discovery no longer fails with magic global callables
|
||||||
|
that provide no sane __code__ object (mock.call for example)
|
||||||
|
|
||||||
- reporting refinements:
|
- reporting refinements:
|
||||||
|
|
||||||
- pytest_report_header now receives a "startdir" so that
|
- pytest_report_header now receives a "startdir" so that
|
||||||
|
|
|
@ -1303,10 +1303,14 @@ class FuncargManager:
|
||||||
obj = getattr(holderobj, name)
|
obj = getattr(holderobj, name)
|
||||||
if not callable(obj):
|
if not callable(obj):
|
||||||
continue
|
continue
|
||||||
|
# to avoid breaking on magic global callables
|
||||||
|
# we explicitly check if we get a sane code object
|
||||||
|
# else having mock.call in the globals fails for example
|
||||||
|
code = py.code.getrawcode(obj)
|
||||||
|
if not inspect.iscode(code):
|
||||||
|
continue
|
||||||
# resource factories either have a pytest_funcarg__ prefix
|
# resource factories either have a pytest_funcarg__ prefix
|
||||||
# or are "funcarg" marked
|
# or are "funcarg" marked
|
||||||
if not callable(obj):
|
|
||||||
continue
|
|
||||||
marker = getattr(obj, "_pytestfactory", None)
|
marker = getattr(obj, "_pytestfactory", None)
|
||||||
if marker is not None:
|
if marker is not None:
|
||||||
assert not name.startswith(self._argprefix)
|
assert not name.startswith(self._argprefix)
|
||||||
|
|
|
@ -1761,6 +1761,23 @@ class TestSetupDiscovery:
|
||||||
reprec = testdir.inline_run("-s")
|
reprec = testdir.inline_run("-s")
|
||||||
reprec.assertoutcome(passed=1)
|
reprec.assertoutcome(passed=1)
|
||||||
|
|
||||||
|
def test_callables_nocode(self, testdir):
|
||||||
|
"""
|
||||||
|
a imported mock.call would break setup/factory discovery
|
||||||
|
due to it being callable and __code__ not being a code object
|
||||||
|
"""
|
||||||
|
testdir.makepyfile("""
|
||||||
|
class _call(tuple):
|
||||||
|
def __call__(self, *k, **kw):
|
||||||
|
pass
|
||||||
|
def __getattr__(self, k):
|
||||||
|
return self
|
||||||
|
|
||||||
|
call = _call()
|
||||||
|
""")
|
||||||
|
reprec = testdir.inline_run("-s")
|
||||||
|
reprec.assertoutcome(failed=0, passed=0)
|
||||||
|
|
||||||
|
|
||||||
class TestSetupManagement:
|
class TestSetupManagement:
|
||||||
def test_funcarg_and_setup(self, testdir):
|
def test_funcarg_and_setup(self, testdir):
|
||||||
|
|
Loading…
Reference in New Issue