summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_venv.py25
-rw-r--r--tox/config.py1
-rw-r--r--tox/hookspecs.py16
-rw-r--r--tox/session.py6
4 files changed, 48 insertions, 0 deletions
diff --git a/tests/test_venv.py b/tests/test_venv.py
index 30bdf3c..0af9977 100644
--- a/tests/test_venv.py
+++ b/tests/test_venv.py
@@ -5,6 +5,7 @@ import os
import sys
import tox.config
from tox.venv import * # noqa
+from tox.hookspecs import hookimpl
from tox.interpreters import NoInterpreterInfo
@@ -672,3 +673,27 @@ def test_tox_testenv_create(newmocksession):
venv = mocksession.getenv('python')
venv.update(action=mocksession.newaction(venv, "getenv"))
assert l == [1, 2]
+
+
+def test_tox_testenv_pre_post(newmocksession):
+ l = []
+
+ class Plugin:
+ @hookimpl
+ def tox_runtest_pre(self, venv):
+ l.append('started')
+
+ @hookimpl
+ def tox_runtest_post(self, venv):
+ l.append('finished')
+
+ mocksession = newmocksession([], """
+ [testenv]
+ commands=testenv_fail
+ """, plugins=[Plugin()])
+
+ venv = mocksession.getenv('python')
+ venv.status = None
+ assert l == []
+ mocksession.runtestenv(venv)
+ assert l == ['started', 'finished']
diff --git a/tox/config.py b/tox/config.py
index bc7ca02..99e678d 100644
--- a/tox/config.py
+++ b/tox/config.py
@@ -38,6 +38,7 @@ def get_plugin_manager(plugins=()):
pm.register(tox.config)
pm.register(tox.interpreters)
pm.register(tox.venv)
+ pm.register(tox.session)
pm.load_setuptools_entrypoints("tox")
for plugin in plugins:
pm.register(plugin)
diff --git a/tox/hookspecs.py b/tox/hookspecs.py
index 36c539c..db589ed 100644
--- a/tox/hookspecs.py
+++ b/tox/hookspecs.py
@@ -41,3 +41,19 @@ def tox_testenv_create(venv, action):
@hookspec
def tox_testenv_install_deps(venv, action):
""" [experimental] perform install dependencies action for this venv. """
+
+
+@hookspec
+def tox_runtest_pre(venv):
+ """ [experimental] perform arbitrary action before running tests for this venv.
+
+ This could be used to indicate that tests for a given venv have started, for intstance.
+ """
+
+
+@hookspec
+def tox_runtest_post(venv):
+ """ [experimental] perform arbitrary action after running tests for this venv.
+
+ This could be used to have per-venv test reporting of pass/fail status.
+ """
diff --git a/tox/session.py b/tox/session.py
index cb5cc66..e29696e 100644
--- a/tox/session.py
+++ b/tox/session.py
@@ -347,6 +347,10 @@ class Session:
raise SystemExit(1)
self._actions = []
+ @property
+ def hook(self):
+ return self.config.pluginmanager.hook
+
def _makevenv(self, name):
envconfig = self.config.envconfigs.get(name, None)
if envconfig is None:
@@ -556,7 +560,9 @@ class Session:
if not self.config.option.notest:
if venv.status:
return
+ self.hook.tox_runtest_pre(venv=venv)
venv.test(redirect=redirect)
+ self.hook.tox_runtest_post(venv=venv)
else:
venv.status = "skipped tests"