From 9ac4faf3af27c782aceab246e62d010c3054b496 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Wed, 21 Oct 2009 18:44:12 +0200 Subject: [PATCH] don't visit '_' attributes on python objects for calling hooks --HG-- branch : trunk --- _py/test/pycollect.py | 7 ++++--- testing/pytest/test_pycollect.py | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/_py/test/pycollect.py b/_py/test/pycollect.py index 225eaf15c..8e6fc4111 100644 --- a/_py/test/pycollect.py +++ b/_py/test/pycollect.py @@ -109,9 +109,10 @@ class PyCollectorMixin(PyobjMixin, py.test.collect.Collector): if name in seen: continue seen[name] = True - res = self.makeitem(name, obj) - if res is not None: - d[name] = res + if name[0] != "_": + res = self.makeitem(name, obj) + if res is not None: + d[name] = res return d def _deprecated_join(self, name): diff --git a/testing/pytest/test_pycollect.py b/testing/pytest/test_pycollect.py index 9e1c95ecb..2ef6de35a 100644 --- a/testing/pytest/test_pycollect.py +++ b/testing/pytest/test_pycollect.py @@ -389,6 +389,14 @@ class TestConftestCustomization: assert len(colitems) == 1 assert colitems[0].name == "check_method" + def test_makeitem_non_underscore(self, testdir, monkeypatch): + modcol = testdir.getmodulecol("def _hello(): pass") + l = [] + monkeypatch.setattr(py.test.collect.Module, 'makeitem', + lambda self, name, obj: l.append(name)) + modcol._buildname2items() + assert '_hello' not in l + class TestReportinfo: