From 241ff0b43ad04d81a423566267d9c045bae1b036 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 26 May 2011 18:56:45 -0500 Subject: [PATCH] add a hook called when a Module is successfully created --- _pytest/hookspec.py | 3 +++ _pytest/python.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) 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)