diff --git a/CHANGELOG b/CHANGELOG index 64710f659..16ebfcf56 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,8 @@ 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 issue213 - allow to parametrize with values like numpy arrays that do not support an __eq__ operator diff --git a/_pytest/python.py b/_pytest/python.py index 3a28f7771..dcf2cccb0 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -1551,7 +1551,15 @@ class FixtureManager: continue # fixture functions have a pytest_funcarg__ prefix (pre-2.3 style) # or are "@pytest.fixture" marked - marker = getattr(obj, "_pytestfixturefunction", None) + 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 = None + if marker is None: if not name.startswith(self._argprefix): continue diff --git a/testing/test_python.py b/testing/test_python.py index 77c206f4c..3a09570f8 100644 --- a/testing/test_python.py +++ b/testing/test_python.py @@ -1611,6 +1611,34 @@ 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("""