diff --git a/_pytest/python.py b/_pytest/python.py index 96eec73df..f145ca5b8 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -277,13 +277,12 @@ class PyCollector(PyobjMixin, pytest.Collector): if name in seen: continue seen[name] = True - if name[0] != "_": - res = self.makeitem(name, obj) - if res is None: - continue - if not isinstance(res, list): - res = [res] - l.extend(res) + res = self.makeitem(name, obj) + if res is None: + continue + if not isinstance(res, list): + res = [res] + l.extend(res) l.sort(key=lambda item: item.reportinfo()[:2]) return l diff --git a/testing/python/collect.py b/testing/python/collect.py index fc41bf738..5f1de8830 100644 --- a/testing/python/collect.py +++ b/testing/python/collect.py @@ -659,6 +659,28 @@ def test_customized_python_discovery(testdir): "*2 passed*", ]) + +def test_customized_python_discovery_functions(testdir): + testdir.makeini(""" + [pytest] + python_functions=_test + """) + p = testdir.makepyfile(""" + def _test_underscore(): + pass + """) + result = testdir.runpytest("--collectonly", "-s") + result.stdout.fnmatch_lines([ + "*_test_underscore*", + ]) + + result = testdir.runpytest() + assert result.ret == 0 + result.stdout.fnmatch_lines([ + "*1 passed*", + ]) + + def test_collector_attributes(testdir): testdir.makeconftest(""" import pytest