[py-svn] r61752 - in py/branch/pytestplugin/py/test: . plugin testing
hpk at codespeak.net
hpk at codespeak.net
Wed Feb 11 19:43:11 CET 2009
Author: hpk
Date: Wed Feb 11 19:43:08 2009
New Revision: 61752
Modified:
py/branch/pytestplugin/py/test/plugin/pytest_eventlog.py
py/branch/pytestplugin/py/test/plugin/pytest_plugintester.py
py/branch/pytestplugin/py/test/plugin/pytest_pocoo.py
py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py
py/branch/pytestplugin/py/test/plugin/pytest_tmpdir.py
py/branch/pytestplugin/py/test/plugin/pytest_unittest.py
py/branch/pytestplugin/py/test/pmanage.py
py/branch/pytestplugin/py/test/testing/test_pmanage.py
Log:
* allow to specify plugins without "pytest_" prefix
* provide explicit plugin class to apicheck()
Modified: py/branch/pytestplugin/py/test/plugin/pytest_eventlog.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_eventlog.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_eventlog.py Wed Feb 11 19:43:08 2009
@@ -27,7 +27,7 @@
# ===============================================================================
def test_generic(plugintester):
- plugintester.apicheck()
+ plugintester.apicheck(Eventlog)
fstester = plugintester.fstester()
fstester.makepyfile(test_one="""
Modified: py/branch/pytestplugin/py/test/plugin/pytest_plugintester.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_plugintester.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_plugintester.py Wed Feb 11 19:43:08 2009
@@ -20,8 +20,6 @@
for colitem in self.pyfuncitem.listchain():
if isinstance(colitem, colitem.Module):
return colitem
- def _getimpname(self):
- return self.getmoditem().obj.__name__
def finalize(self):
""" called after test function finished execution"""
@@ -31,19 +29,17 @@
# XXX import differently, eg.
# FSTester = self.pyfuncitem._config.pluginmanager.getpluginattr("pytester", "FSTester")
from pytest_pytester import FSTester
- impname = self._getimpname()
crunner = FSTester(self.pyfuncitem)
- crunner.ensureplugin(impname)
+ #
+ #crunner.ensureplugin(impname)
return crunner
- def apicheck(self, impname=None):
+ def apicheck(self, impclass):
from py.__.test.pmanage import PluginManager
- if not impname:
- impname = self.getmoditem().obj.__name__
- print "loading and checking", impname
+ print "loading and checking", impclass
fail = False
pm = PluginManager()
- plugin = pm.import_plugin(impname)
+ plugin = pm.import_plugin(impclass)
methods = collectattr(plugin.__class__)
hooks = collectattr(PytestPluginHooks)
getargs = py.std.inspect.getargs
@@ -135,4 +131,4 @@
# ===============================================================================
def test_generic(plugintester):
- plugintester.apicheck()
+ plugintester.apicheck(Plugintester)
Modified: py/branch/pytestplugin/py/test/plugin/pytest_pocoo.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_pocoo.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_pocoo.py Wed Feb 11 19:43:08 2009
@@ -37,7 +37,7 @@
break
def test_apicheck(plugintester):
- plugintester.apicheck()
+ plugintester.apicheck(Pocoo)
def test_toproxy(fstester):
fstester.makepyfile(conftest="pytest_plugins='pytest_pocoo',")
Modified: py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_resultlog.py Wed Feb 11 19:43:08 2009
@@ -241,7 +241,7 @@
assert 'ValueError' in entry
def test_generic(plugintester, linecomp):
- plugintester.apicheck()
+ plugintester.apicheck(Resultlog)
fstester = plugintester.fstester()
fstester.makepyfile(test_one="""
import py
Modified: py/branch/pytestplugin/py/test/plugin/pytest_tmpdir.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_tmpdir.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_tmpdir.py Wed Feb 11 19:43:08 2009
@@ -26,7 +26,7 @@
# ===============================================================================
#
def test_generic(plugintester):
- plugintester.apicheck()
+ plugintester.apicheck(Tmpdir)
def test_pyitemexecute_arg():
class Pseudoitem:
Modified: py/branch/pytestplugin/py/test/plugin/pytest_unittest.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_unittest.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_unittest.py Wed Feb 11 19:43:08 2009
@@ -71,7 +71,7 @@
def test_generic(plugintester):
- plugintester.apicheck()
+ plugintester.apicheck(Unittest)
def test_simple_unittest(fstester):
testpath = fstester.makepyfile(test_simple_unittest="""
Modified: py/branch/pytestplugin/py/test/pmanage.py
==============================================================================
--- py/branch/pytestplugin/py/test/pmanage.py (original)
+++ py/branch/pytestplugin/py/test/pmanage.py Wed Feb 11 19:43:08 2009
@@ -34,16 +34,17 @@
if not isinstance(importspec, basestring):
return self.addpluginclass(importspec)
else:
- lastpart = importspec.split(".")[-1]
modprefix = "pytest_"
- if not lastpart.startswith(modprefix):
- raise ValueError("in importspec %r: %r does not start with %r"
- %(importspec, lastpart, modprefix))
+ if not importspec.startswith(modprefix):
+ importspec = modprefix + importspec
try:
- mod = __import__(importspec, None, None, "__doc__")
+ mod = __import__(importspec)
except ImportError, e:
- mod = __import__("py.__.test.plugin.%s" %(importspec), None, None, '__doc__')
- clsname = lastpart[len(modprefix):].capitalize()
+ try:
+ mod = __import__("py.__.test.plugin.%s" %(importspec), None, None, '__doc__')
+ except ImportError:
+ raise ImportError(importspec)
+ clsname = importspec[len(modprefix):].capitalize()
pluginclass = getattr(mod, clsname)
result = self.addpluginclass(pluginclass)
self.consider_module(mod)
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 Wed Feb 11 19:43:08 2009
@@ -11,8 +11,8 @@
def test_import_plugin_importname(self):
pm = PluginManager()
- py.test.raises(ValueError, 'pm.import_plugin("x.y")')
- py.test.raises(ValueError, 'pm.import_plugin("pytest_x.y")')
+ py.test.raises(ImportError, 'pm.import_plugin("x.y")')
+ py.test.raises(ImportError, 'pm.import_plugin("pytest_x.y")')
sys.path.insert(0, str(self.tmpdir))
try:
@@ -21,7 +21,8 @@
class Hello:
pass
"""))
- pm.import_plugin(pluginname)
+ pm.import_plugin("hello")
+ pm.import_plugin("pytest_hello")
plugin = pm.getplugin("hello")
finally:
sys.path.remove(str(self.tmpdir))
More information about the pytest-commit
mailing list