[py-svn] r61274 - in py/branch/pytestplugin/py/test: . testing
hpk at codespeak.net
hpk at codespeak.net
Fri Jan 23 17:52:17 CET 2009
Author: hpk
Date: Fri Jan 23 17:52:16 2009
New Revision: 61274
Modified:
py/branch/pytestplugin/py/test/cmdline.py
py/branch/pytestplugin/py/test/config.py
py/branch/pytestplugin/py/test/pmanage.py
py/branch/pytestplugin/py/test/session.py
py/branch/pytestplugin/py/test/testing/plugintester.py
py/branch/pytestplugin/py/test/testing/test_config.py
py/branch/pytestplugin/py/test/testing/test_pmanage.py
Log:
move plugin configure/unconfigure and eventbus initialization to pluginmanager
thus making it independent from session handling
Modified: py/branch/pytestplugin/py/test/cmdline.py
==============================================================================
--- py/branch/pytestplugin/py/test/cmdline.py (original)
+++ py/branch/pytestplugin/py/test/cmdline.py Fri Jan 23 17:52:16 2009
@@ -10,8 +10,10 @@
args = py.std.sys.argv[1:]
config = py.test.config
config.parse(args)
+ config.pluginmanager.configure(config)
session = config.initsession()
exitstatus = session.main()
+ config.pluginmanager.unconfigure(config)
raise SystemExit(exitstatus)
def warn_about_missing_assertion():
Modified: py/branch/pytestplugin/py/test/config.py
==============================================================================
--- py/branch/pytestplugin/py/test/config.py (original)
+++ py/branch/pytestplugin/py/test/config.py Fri Jan 23 17:52:16 2009
@@ -4,6 +4,7 @@
from conftesthandle import Conftest
from py.__.test.defaultconftest import adddefaultoptions
from py.__.test.pmanage import PluginManager
+from py.__.test.event import EventBus
optparse = py.compat.optparse
@@ -35,6 +36,7 @@
self._parser = optparse.OptionParser(
usage="usage: %prog [options] [query] [filenames of tests]")
self._conftest = Conftest()
+ self.bus = EventBus()
self.pluginmanager = PluginManager()
def parse(self, args):
@@ -72,6 +74,7 @@
self._mergerepr(self._repr)
self.pluginmanager.registerplugins(self._conftest.getconftestmodules(None))
del self._repr
+ self.pluginmanager.configure(self)
def _makerepr(self):
l = []
Modified: py/branch/pytestplugin/py/test/pmanage.py
==============================================================================
--- py/branch/pytestplugin/py/test/pmanage.py (original)
+++ py/branch/pytestplugin/py/test/pmanage.py Fri Jan 23 17:52:16 2009
@@ -45,6 +45,9 @@
for mod in conftestmodules:
self.consider_module(mod)
+ #
+ # API for interacting with registered and instantiated plugin objects
+ #
def add_cmdlineoptions(self, config):
# XXX think about sorting/grouping of options from user-perspective
opts = []
@@ -52,10 +55,8 @@
opts.extend(options)
config.addoptions("ungrouped options added by plugins", *opts)
- #
- # API for calling methods of registered plugins
- #
def callplugins(self, methname, **args):
+ """ call method with the given name for each plugin. pass along kwargs. """
for name, method in self.listattr(methname):
method(**args)
@@ -72,3 +73,13 @@
continue
return l
+ def configure(self, config):
+ # XXX if we want to allow post-configure addition of
+ # plugins this logic here has to be refined
+ assert self.forward_event not in config.bus._subscribers
+ config.bus._subscribers.append(self.forward_event)
+ self.callplugins("pytest_configure", config=config)
+
+ def unconfigure(self, config):
+ self.callplugins("pytest_unconfigure", config=config)
+ config.bus._subscribers.remove(self.forward_event)
Modified: py/branch/pytestplugin/py/test/session.py
==============================================================================
--- py/branch/pytestplugin/py/test/session.py (original)
+++ py/branch/pytestplugin/py/test/session.py Fri Jan 23 17:52:16 2009
@@ -24,7 +24,7 @@
"""
def __init__(self, config):
self.config = config
- self.bus = EventBus()
+ self.bus = config.bus # shortcut
self._nomatch = False
def fixoptions(self):
@@ -85,8 +85,6 @@
def sessionstarts(self):
""" setup any neccessary resources ahead of the test run. """
- self.config.pluginmanager.callplugins("pytest_configure", config=self.config)
- self.bus.subscribe(self.config.pluginmanager.forward_event)
self.bus.notify(event.TestrunStart())
# XXX the following is not used or neccessary for the DSession subclass
self._failurelist = []
@@ -103,11 +101,6 @@
self.bus.notify(event.TestrunFinish(exitstatus=exitstatus,
excinfo=excinfo))
self.bus.unsubscribe(self._processfailures)
- # XXX call plugin's unconfigure and write tests for
- # that, conflicts with looponfailing/remote's sending
- # of an event after the session has finished.
- #self.bus.unsubscribe(self.config.pluginmanager.forward_event)
- #self.config.pluginmanager.callplugins("pytest_unconfigure", config=self.config)
return self._failurelist
def getinitialitems(self, colitems):
Modified: py/branch/pytestplugin/py/test/testing/plugintester.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/plugintester.py (original)
+++ py/branch/pytestplugin/py/test/testing/plugintester.py Fri Jan 23 17:52:16 2009
@@ -56,12 +56,10 @@
pass # already registered
plugin = config.pluginmanager.getplugin(pname)
assert plugin
- if hasattr(plugin, 'pytest_configure'):
- plugin.pytest_configure(config)
+ config.pluginmanager.configure(config)
session = config.initsession()
exitstatus = session.main()
- if hasattr(plugin, 'pytest_unconfigure'):
- plugin.pytest_unconfigure(config)
+ config.pluginmanager.unconfigure(config)
return tmpdir
finally:
olddir.chdir()
Modified: py/branch/pytestplugin/py/test/testing/test_config.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_config.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_config.py Fri Jan 23 17:52:16 2009
@@ -115,6 +115,10 @@
config2._initialized = False # we have to do that from tests
config2._repr = config._makerepr()
config2._initafterpickle(topdir=tmp.dirpath())
+ # we check that config "remote" config objects
+ # have correct plugin initialization
+ assert config2.pluginmanager._plugins
+ assert config2.pluginmanager.forward_event in config2.bus._subscribers
for col1, col2 in zip(getcolitems(config), getcolitems(config2)):
assert col1.fspath == col2.fspath
cols = getcolitems(config2)
@@ -138,7 +142,6 @@
assert config.getvalue('x') == 1
config._mergerepr(repr2)
assert config.option.verbose == 42
-
def test_config_rconfig():
tmp = py.test.ensuretemp("rconfigopt")
Modified: py/branch/pytestplugin/py/test/testing/test_pmanage.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_pmanage.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_pmanage.py Fri Jan 23 17:52:16 2009
@@ -2,6 +2,7 @@
import py
from py.__.test.pmanage import PluginManager
from py.__.test.event import NOP
+from py.__.test.config import Config as pytestConfig
class TestPluginManager:
def setup_method(self, method):
@@ -87,6 +88,22 @@
assert not pm.listattr("hello")
assert pm.listattr("x") == [('my2', 42)]
+ def test_eventbus_interaction(self):
+ pm = PluginManager()
+ l = []
+ class My3:
+ def pytest_configure(self, config):
+ l.append("configure")
+ def pytest_unconfigure(self, config):
+ l.append("unconfigure")
+ pm.addpluginclass(My3)
+ config = pytestConfig()
+ pm.configure(config)
+ assert pm.forward_event in config.bus._subscribers
+ pm.unconfigure(config)
+ assert pm.forward_event not in config.bus._subscribers
+ assert l == ['configure', 'unconfigure']
+
def test_pytest_event(self):
pm = PluginManager()
l = []
@@ -100,15 +117,15 @@
assert l[0] is ev
def test_addcmdlineoptions(self):
- from py.__.test.config import Config
pm = PluginManager()
class My:
pytest_cmdlineoptions = [
py.test.config.Option("--hello", dest="dest", default=242)
]
pm.addpluginclass(My)
- config = Config()
+ config = pytestConfig()
pm.add_cmdlineoptions(config)
opt = config._parser.get_option("--hello")
assert opt
assert opt.default == 242
+
More information about the pytest-commit
mailing list