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 Changes between 2.3.2 and 2.3.3.dev
----------------------------------- -----------------------------------
- fix issue 214: gracefully handle proxy objects that - fix issue214 - parse modules that contain special objects like e. g.
look like fixtures but raise exceptions on introspection 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 - fix issue213 - allow to parametrize with values like numpy arrays that
do not support an __eq__ operator do not support an __eq__ operator
Changes between 2.3.1 and 2.3.2 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) # fixture functions have a pytest_funcarg__ prefix (pre-2.3 style)
# or are "@pytest.fixture" marked # or are "@pytest.fixture" marked
try: try:
marker = getattr(obj, "_pytestfixturefunction", None) marker = obj._pytestfixturefunction
except RuntimeError: except KeyboardInterrupt:
# some proxy objects raise RuntimeError raise
# flasks request globals are one example except Exception:
# those aren't fixture functions, so we can ignore # some objects raise errors like request (from flask import request)
# XXX: maybe trace it when it happens? # we don't expect them to be fixture functions
marker = None marker = None
if marker is None: if marker is None:

View File

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

View File

@ -24,7 +24,7 @@ def main():
name='pytest', name='pytest',
description='py.test: simple powerful testing with Python', description='py.test: simple powerful testing with Python',
long_description = long_description, long_description = long_description,
version='2.3.2', version='2.3.3.dev1',
url='http://pytest.org', url='http://pytest.org',
license='MIT license', license='MIT license',
platforms=['unix', 'linux', 'osx', 'cygwin', 'win32'], 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() 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: class TestReportInfo:
def test_itemreport_reportinfo(self, testdir, linecomp): def test_itemreport_reportinfo(self, testdir, linecomp):
testdir.makeconftest(""" testdir.makeconftest("""
@ -2145,6 +2118,20 @@ class TestFixtureManager:
""") """)
return testdir 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): def test_parsefactories_conftest(self, testdir):
testdir.makepyfile(""" testdir.makepyfile("""
def test_hello(item, fm): def test_hello(item, fm):