[svn r62615] implement a use case for avoiding recursion into a directory.
--HG-- branch : trunk
This commit is contained in:
parent
2d98dbfc81
commit
13dacf38eb
|
@ -448,6 +448,9 @@ class Directory(FSCollector):
|
||||||
def consider_dir(self, path, usefilters=None):
|
def consider_dir(self, path, usefilters=None):
|
||||||
if usefilters is not None:
|
if usefilters is not None:
|
||||||
APIWARN("0.99", "usefilters argument not needed")
|
APIWARN("0.99", "usefilters argument not needed")
|
||||||
|
res = self._config.pytestplugins.call_firstresult(
|
||||||
|
'pytest_collect_recurse', path=path, parent=self)
|
||||||
|
if res is None or res:
|
||||||
return self._config.pytestplugins.call_each(
|
return self._config.pytestplugins.call_each(
|
||||||
'pytest_collect_directory', path=path, parent=self)
|
'pytest_collect_directory', path=path, parent=self)
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,16 @@ class PytestPluginHooks:
|
||||||
def pytest_collect_file(self, path, parent):
|
def pytest_collect_file(self, path, parent):
|
||||||
""" return Collection node or None. """
|
""" return Collection node or None. """
|
||||||
|
|
||||||
|
def pytest_collect_recurse(self, path, parent):
|
||||||
|
""" return True/False to cause/prevent recursion into given directory.
|
||||||
|
return None if you do not want to make the decision.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def pytest_collect_directory(self, path, parent):
|
||||||
|
""" return Collection node or None. """
|
||||||
|
|
||||||
def pytest_pymodule_makeitem(self, modcol, name, obj):
|
def pytest_pymodule_makeitem(self, modcol, name, obj):
|
||||||
""" return custom item/collector or None. """
|
""" return custom item/collector for a python object in a module, or None. """
|
||||||
|
|
||||||
# from pytest_terminal plugin
|
# from pytest_terminal plugin
|
||||||
def pytest_report_teststatus(self, event):
|
def pytest_report_teststatus(self, event):
|
||||||
|
|
|
@ -197,6 +197,22 @@ class TestCustomConftests:
|
||||||
assert item.name == "hello.xxx"
|
assert item.name == "hello.xxx"
|
||||||
assert item.__class__.__name__ == "CustomItem"
|
assert item.__class__.__name__ == "CustomItem"
|
||||||
|
|
||||||
|
def test_avoid_directory_on_option(self, testdir):
|
||||||
|
testdir.makeconftest("""
|
||||||
|
class ConftestPlugin:
|
||||||
|
def pytest_addoption(self, parser):
|
||||||
|
parser.addoption("--XX", action="store_true", default=False)
|
||||||
|
def pytest_collect_recurse(self, path, parent):
|
||||||
|
return parent._config.getvalue("XX")
|
||||||
|
""")
|
||||||
|
testdir.mkdir("hello")
|
||||||
|
evrec = testdir.inline_run(testdir.tmpdir)
|
||||||
|
names = [rep.colitem.name for rep in evrec.getnamed("collectionreport")]
|
||||||
|
assert 'hello' not in names
|
||||||
|
evrec = testdir.inline_run(testdir.tmpdir, "--XX")
|
||||||
|
names = [rep.colitem.name for rep in evrec.getnamed("collectionreport")]
|
||||||
|
assert 'hello' in names
|
||||||
|
|
||||||
class TestCollectorReprs:
|
class TestCollectorReprs:
|
||||||
def test_repr_metainfo_basic_item(self, testdir):
|
def test_repr_metainfo_basic_item(self, testdir):
|
||||||
modcol = testdir.getmodulecol("")
|
modcol = testdir.getmodulecol("")
|
||||||
|
|
Loading…
Reference in New Issue