diff options
Diffstat (limited to 'coverage/runners/pytestplugin.py')
-rw-r--r-- | coverage/runners/pytestplugin.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/coverage/runners/pytestplugin.py b/coverage/runners/pytestplugin.py new file mode 100644 index 00000000..af825aa9 --- /dev/null +++ b/coverage/runners/pytestplugin.py @@ -0,0 +1,34 @@ +"""py.test plugin hooks""" + +from coverage.runners.plugin import CoverageTestWrapper, options + +def pytest_addoption(parser): + """Get all the options from the coverage.runner and import them.""" + group = parser.getgroup('Coverage options') + for opt in options: + group._addoption_instance(opt) + +def pytest_configure(config): + """Load the runner and start it up.""" + if config.getvalue("cover_actions"): + config.pluginmanager.register(CoveragePlugin(config), "do_coverage") + +class CoveragePlugin: + """The py.test coverage plugin.""" + + def __init__(self, config): + self.config = config + + def pytest_sessionstart(self): + """Called before session.main() is called.""" + self.coverage = CoverageTestWrapper(self.config.option) + # XXX maybe better to start/suspend/resume coverage + # for each single test item + self.coverage.start() + + def pytest_terminal_summary(self, terminalreporter): + """Add an additional section in the terminal summary reporting.""" + tw = terminalreporter._tw + tw.sep('-', 'coverage') + tw.line('Processing Coverage...') + self.coverage.finish() |