From 4e3a8077330a20488eb818a1f280c4bd5a37fc67 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Mon, 28 Sep 2015 13:34:28 +0200 Subject: [PATCH] fix issue #1073 -- shortcut plugin hook lookup if the attrname is not prefixed with pytest_. --- _pytest/config.py | 6 ++++++ testing/test_conftest.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/_pytest/config.py b/_pytest/config.py index def26a02b..c327436ad 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -174,6 +174,12 @@ class PytestPluginManager(PluginManager): if exclude_pytest_names(name): return None + # pytest hooks are always prefixed with pytest_ + # so we avoid accessing possibly non-readable attributes + # (see issue #1073) + if not name.startswith("pytest_"): + return + method = getattr(plugin, name) opts = super(PytestPluginManager, self).parse_hookimpl_opts(plugin, name) if opts is not None: diff --git a/testing/test_conftest.py b/testing/test_conftest.py index 6700502c4..a0b77cfa5 100644 --- a/testing/test_conftest.py +++ b/testing/test_conftest.py @@ -388,3 +388,19 @@ def test_search_conftest_up_to_inifile(testdir, confcutdir, passed, error): if error: match += '*%d error*' % error result.stdout.fnmatch_lines(match) + + +def test_issue1073_conftest_special_objects(testdir): + testdir.makeconftest(""" + class DontTouchMe: + def __getattr__(self, x): + raise Exception('cant touch me') + + x = DontTouchMe() + """) + testdir.makepyfile(""" + def test_some(): + pass + """) + res = testdir.runpytest() + assert res.ret == 0