introduce new pytest_pycollect_makemodule(path, parent) hook for
allowing customization of the Module collection object for a matching test module. --HG-- branch : trunk
This commit is contained in:
parent
811408959f
commit
962d0fe2be
|
@ -14,6 +14,9 @@ Changes between 1.2.1 and 1.2.2 (release pending)
|
||||||
def pytest_ignore_collect_path(path):
|
def pytest_ignore_collect_path(path):
|
||||||
return path.check(link=1)
|
return path.check(link=1)
|
||||||
to prevent even a collection try of any tests in symlinked dirs.
|
to prevent even a collection try of any tests in symlinked dirs.
|
||||||
|
- introduce new pytest_pycollect_makemodule(path, parent) hook for
|
||||||
|
allowing customization of the Module collection object for a
|
||||||
|
matching test module.
|
||||||
- expose previously internal commonly useful methods:
|
- expose previously internal commonly useful methods:
|
||||||
py.io.get_terminal_with() -> return terminal width
|
py.io.get_terminal_with() -> return terminal width
|
||||||
py.io.ansi_print(...) -> print colored/bold text on linux/win32
|
py.io.ansi_print(...) -> print colored/bold text on linux/win32
|
||||||
|
|
|
@ -62,6 +62,14 @@ def pytest_itemstart(item, node=None):
|
||||||
# Python test function related hooks
|
# Python test function related hooks
|
||||||
# -------------------------------------------------------------------------
|
# -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
def pytest_pycollect_makemodule(path, parent):
|
||||||
|
""" return a Module collector or None for the given path.
|
||||||
|
This hook will be called for each matching test module path.
|
||||||
|
The pytest_collect_file hook needs to be used if you want to
|
||||||
|
create test modules for files that do not match as a test module.
|
||||||
|
"""
|
||||||
|
pytest_pycollect_makemodule.firstresult = True
|
||||||
|
|
||||||
def pytest_pycollect_makeitem(collector, name, obj):
|
def pytest_pycollect_makeitem(collector, name, obj):
|
||||||
""" return custom item/collector for a python object in a module, or None. """
|
""" return custom item/collector for a python object in a module, or None. """
|
||||||
pytest_pycollect_makeitem.firstresult = True
|
pytest_pycollect_makeitem.firstresult = True
|
||||||
|
|
|
@ -18,7 +18,11 @@ def pytest_collect_file(path, parent):
|
||||||
if pb.startswith("test_") or pb.endswith("_test") or \
|
if pb.startswith("test_") or pb.endswith("_test") or \
|
||||||
path in parent.config._argfspaths:
|
path in parent.config._argfspaths:
|
||||||
if ext == ".py":
|
if ext == ".py":
|
||||||
return parent.Module(path, parent=parent)
|
return parent.ihook.pytest_pycollect_makemodule(
|
||||||
|
path=path, parent=parent)
|
||||||
|
|
||||||
|
def pytest_pycollect_makemodule(path, parent):
|
||||||
|
return parent.Module(path, parent)
|
||||||
|
|
||||||
def pytest_funcarg__pytestconfig(request):
|
def pytest_funcarg__pytestconfig(request):
|
||||||
""" the pytest config object with access to command line opts."""
|
""" the pytest config object with access to command line opts."""
|
||||||
|
|
|
@ -313,6 +313,23 @@ class TestSorting:
|
||||||
|
|
||||||
|
|
||||||
class TestConftestCustomization:
|
class TestConftestCustomization:
|
||||||
|
def test_pytest_pycollect_module(self, testdir):
|
||||||
|
testdir.makeconftest("""
|
||||||
|
import py
|
||||||
|
class MyModule(py.test.collect.Module):
|
||||||
|
pass
|
||||||
|
def pytest_pycollect_makemodule(path, parent):
|
||||||
|
if path.basename == "test_xyz.py":
|
||||||
|
return MyModule(path, parent)
|
||||||
|
""")
|
||||||
|
testdir.makepyfile("def some(): pass")
|
||||||
|
testdir.makepyfile(test_xyz="")
|
||||||
|
result = testdir.runpytest("--collectonly")
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*<Module*test_pytest*",
|
||||||
|
"*<MyModule*xyz*",
|
||||||
|
])
|
||||||
|
|
||||||
def test_pytest_pycollect_makeitem(self, testdir):
|
def test_pytest_pycollect_makeitem(self, testdir):
|
||||||
testdir.makeconftest("""
|
testdir.makeconftest("""
|
||||||
import py
|
import py
|
||||||
|
|
Loading…
Reference in New Issue