diff --git a/_pytest/hookspec.py b/_pytest/hookspec.py index 7cb60a131..99ae77d55 100644 --- a/_pytest/hookspec.py +++ b/_pytest/hookspec.py @@ -104,6 +104,9 @@ def pytest_pycollect_makemodule(path, parent): """ pytest_pycollect_makemodule.firstresult = True +def pytest_pycollect_onmodule(mod): + """ Called when a module is collected.""" + def pytest_pycollect_before_module_import(mod): """Called before a module is imported.""" diff --git a/_pytest/python.py b/_pytest/python.py index 5d1ad4713..615e01a0c 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -60,8 +60,11 @@ def pytest_collect_file(path, parent): break else: return - return parent.ihook.pytest_pycollect_makemodule( + mod = parent.ihook.pytest_pycollect_makemodule( path=path, parent=parent) + if mod is not None: + parent.ihook.pytest_pycollect_onmodule(mod=mod) + return mod def pytest_pycollect_makemodule(path, parent): return Module(path, parent)