extended - fix issue214 - ignore attribute-access errors with objects in test modules that can blow up (for example flask's request object)

This commit is contained in:
holger krekel 2012-10-31 17:00:55 +01:00
parent 983b2d2475
commit fb173a97a8
6 changed files with 30 additions and 41 deletions

View File

@ -1,11 +1,13 @@
Changes between 2.3.2 and 2.3.3.dev
-----------------------------------
- fix issue 214: gracefully handle proxy objects that
look like fixtures but raise exceptions on introspection
- fix issue214 - parse modules that contain special objects like e. g.
flask's request object which blows up on getattr access if no request
is active.
- fix issue213 - allow to parametrize with values like numpy arrays that
do not support an __eq__ operator
Changes between 2.3.1 and 2.3.2
-----------------------------------

View File

@ -1,2 +1,2 @@
#
__version__ = '2.3.2'
__version__ = '2.3.3.dev1'

View File

@ -1552,12 +1552,12 @@ class FixtureManager:
# fixture functions have a pytest_funcarg__ prefix (pre-2.3 style)
# or are "@pytest.fixture" marked
try:
marker = getattr(obj, "_pytestfixturefunction", None)
except RuntimeError:
# some proxy objects raise RuntimeError
# flasks request globals are one example
# those aren't fixture functions, so we can ignore
# XXX: maybe trace it when it happens?
marker = obj._pytestfixturefunction
except KeyboardInterrupt:
raise
except Exception:
# some objects raise errors like request (from flask import request)
# we don't expect them to be fixture functions
marker = None
if marker is None:

View File

@ -2,7 +2,7 @@
import pytest
def pytest_collect_file(path, parent):
def pytest_collect_file(parent, path):
if path.ext == ".yml" and path.basename.startswith("test"):
return YamlFile(path, parent)

View File

@ -24,7 +24,7 @@ def main():
name='pytest',
description='py.test: simple powerful testing with Python',
long_description = long_description,
version='2.3.2',
version='2.3.3.dev1',
url='http://pytest.org',
license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'],

View File

@ -1612,33 +1612,6 @@ def test_funcarg_lookup_error(testdir):
assert "INTERNAL" not in result.stdout.str()
def test_funcarg_fixture_discovery_failure_issue214(testdir):
# some proxy objects raise RuntimeError on getattr
# for example flask.request
p = testdir.makepyfile("""
class EvilObject(object):
def __call__(self):
#needed to trick discovery
pass
def __getattr__(self, arg):
raise RuntimeError('uhm ' + arg)
fixture = EvilObject()
def test_1():
pass
""")
result = testdir.runpytest('--fulltrace')
result.stdout.fnmatch_lines([
'*1 passed*'
])
assert "INTERNAL" not in result.stdout.str()
assert "ERROR" not in result.stdout.str()
class TestReportInfo:
def test_itemreport_reportinfo(self, testdir, linecomp):
testdir.makeconftest("""
@ -2145,6 +2118,20 @@ class TestFixtureManager:
""")
return testdir
def test_parsefactories_evil_objects_issue214(self, testdir):
testdir.makepyfile("""
class A:
def __call__(self):
pass
def __getattr__(self, name):
raise RuntimeError()
a = A()
def test_hello():
pass
""")
reprec = testdir.inline_run()
reprec.assertoutcome(passed=1, failed=0)
def test_parsefactories_conftest(self, testdir):
testdir.makepyfile("""
def test_hello(item, fm):