[py-svn] r63808 - in py/trunk/py: . misc/testing test test/plugin
hpk at codespeak.net
hpk at codespeak.net
Tue Apr 7 22:46:51 CEST 2009
Author: hpk
Date: Tue Apr 7 22:46:50 2009
New Revision: 63808
Modified:
py/trunk/py/__init__.py
py/trunk/py/_com.py
py/trunk/py/misc/testing/test_com.py
py/trunk/py/test/config.py
py/trunk/py/test/plugin/api.py
py/trunk/py/test/plugin/pytest_default.py
py/trunk/py/test/plugin/pytest_runner.py
py/trunk/py/test/pytestplugin.py
Log:
* refinements/renames to new PluginAPI
* have pytest_runner start to use it, passes the main test
Modified: py/trunk/py/__init__.py
==============================================================================
--- py/trunk/py/__init__.py (original)
+++ py/trunk/py/__init__.py Tue Apr 7 22:46:50 2009
@@ -57,7 +57,7 @@
'_com.PyPlugins' : ('./_com.py', 'PyPlugins'),
'_com.MultiCall' : ('./_com.py', 'MultiCall'),
'_com.pyplugins' : ('./_com.py', 'pyplugins'),
- '_com.MultiAPI' : ('./_com.py', 'MultiAPI'),
+ '_com.PluginAPI' : ('./_com.py', 'PluginAPI'),
# py lib cmdline tools
'cmdline.pytest' : ('./cmdline/pytest.py', 'main',),
Modified: py/trunk/py/_com.py
==============================================================================
--- py/trunk/py/_com.py (original)
+++ py/trunk/py/_com.py Tue Apr 7 22:46:50 2009
@@ -159,14 +159,16 @@
MultiCall(self.listattr("pyevent"), eventname, args, kwargs).execute()
-class MultiAPI:
- def __init__(self, apiclass, plugins, prefix):
- for fullname in vars(apiclass):
- if fullname[:2] != "__":
- assert fullname.startswith(prefix)
- name = fullname[len(prefix):]
- mm = CallMaker(plugins, fullname)
+class PluginAPI:
+ def __init__(self, apiclass, plugins):
+ self._apiclass = apiclass
+ self._plugins = plugins
+ for name in vars(apiclass):
+ if name[:2] != "__":
+ mm = CallMaker(plugins, name)
setattr(self, name, mm)
+ def __repr__(self):
+ return "<PluginAPI %r %r>" %(self._apiclass, self._plugins)
class CallMaker:
def __init__(self, plugins, name):
Modified: py/trunk/py/misc/testing/test_com.py
==============================================================================
--- py/trunk/py/misc/testing/test_com.py (original)
+++ py/trunk/py/misc/testing/test_com.py Tue Apr 7 22:46:50 2009
@@ -2,7 +2,7 @@
import py
import os
from py._com import PyPlugins, MultiCall
-from py._com import MultiAPI
+from py._com import PluginAPI
pytest_plugins = "xfail"
@@ -254,15 +254,14 @@
def test_happypath(self):
plugins = PyPlugins()
class Api:
- def xyz_hello(self, arg):
+ def hello(self, arg):
pass
- mcm = MultiAPI(apiclass=Api, plugins=plugins, prefix="xyz_")
+ mcm = PluginAPI(apiclass=Api, plugins=plugins)
assert hasattr(mcm, 'hello')
- assert repr(mcm.hello).find("xyz_hello") != -1
- assert not hasattr(mcm, 'xyz_hello')
+ assert repr(mcm.hello).find("hello") != -1
class Plugin:
- def xyz_hello(self, arg):
+ def hello(self, arg):
return arg + 1
plugins.register(Plugin())
l = mcm.hello(3)
Modified: py/trunk/py/test/config.py
==============================================================================
--- py/trunk/py/test/config.py (original)
+++ py/trunk/py/test/config.py Tue Apr 7 22:46:50 2009
@@ -42,6 +42,7 @@
self.pytestplugins = pytestplugins
self._conftest = Conftest(onimport=self._onimportconftest)
self._setupstate = SetupState()
+ self.api = pytestplugins._getapi()
def _onimportconftest(self, conftestmodule):
self.trace("loaded conftestmodule %r" %(conftestmodule,))
Modified: py/trunk/py/test/plugin/api.py
==============================================================================
--- py/trunk/py/test/plugin/api.py (original)
+++ py/trunk/py/test/plugin/api.py Tue Apr 7 22:46:50 2009
@@ -39,6 +39,10 @@
def pytest_itemrun(self, item, pdb=None):
""" run given test item and return test report. """
+ def pytest_item_runtest_finished(self, item, excinfo, outerr):
+ """ called in-process after runtest() returned. """
+
+
# ------------------------------------------------------------------------------
# runtest related hooks
# ------------------------------------------------------------------------------
Modified: py/trunk/py/test/plugin/pytest_default.py
==============================================================================
--- py/trunk/py/test/plugin/pytest_default.py (original)
+++ py/trunk/py/test/plugin/pytest_default.py Tue Apr 7 22:46:50 2009
@@ -17,7 +17,7 @@
from py.__.test import runner
return runner.ItemTestReport(item, excinfo, when, outerr)
- def pyevent__item_runtest_finished(self, item, excinfo, outerr):
+ def pytest_item_runtest_finished(self, item, excinfo, outerr):
from py.__.test import runner
rep = runner.ItemTestReport(item, excinfo, "execute", outerr)
item.config.pytestplugins.notify("itemtestreport", rep)
Modified: py/trunk/py/test/plugin/pytest_runner.py
==============================================================================
--- py/trunk/py/test/plugin/pytest_runner.py (original)
+++ py/trunk/py/test/plugin/pytest_runner.py Tue Apr 7 22:46:50 2009
@@ -1,4 +1,5 @@
import py
+from outcome import Skipped
class RunnerPlugin:
def pytest_configure(self, config):
@@ -15,7 +16,7 @@
item.config.pytestplugins.notify("itemsetupreport", rep)
else:
call = item.config.guardedcall(lambda: item.runtest())
- item.config.mc.pytest_item_runtest_finished(
+ item.config.api.pytest_item_runtest_finished(
item=item, excinfo=call.excinfo, outerr=call.outerr)
call = item.config.guardedcall(lambda: self.teardown_exact(item))
if call.excinfo:
@@ -203,17 +204,15 @@
assert not hasattr(item.parent.obj, 'x')
class TestRunnerPlugin:
- disabled = True
def test_pytest_item_setup_and_runtest(self, testdir):
item = testdir.getitem("""def test_func(): pass""")
plugin = RunnerPlugin()
plugin.pytest_configure(item.config)
sorter = testdir.geteventrecorder(item.config)
plugin.pytest_item_setup_and_runtest(item)
- rep = sorter.getreport("itemtestreport")
+ rep = sorter.getcall("itemtestreport").rep
assert rep.passed
-
class TestSetupEvents:
disabled = True
Modified: py/trunk/py/test/pytestplugin.py
==============================================================================
--- py/trunk/py/test/pytestplugin.py (original)
+++ py/trunk/py/test/pytestplugin.py Tue Apr 7 22:46:50 2009
@@ -2,6 +2,7 @@
handling py.test plugins.
"""
import py
+from py.__.test.plugin import api
class PytestPlugins(object):
def __init__(self, pyplugins=None):
@@ -11,6 +12,10 @@
self.MultiCall = self.pyplugins.MultiCall
self._plugins = {}
+ def _getapi(self):
+ return py._com.PluginAPI(apiclass=api.PluginHooks,
+ plugins=self.pyplugins)
+
def register(self, plugin):
self.pyplugins.register(plugin)
def unregister(self, plugin):
More information about the pytest-commit
mailing list