[py-svn] r62001 - in py/branch/pytestplugin/py/test: . plugin testing
hpk at codespeak.net
hpk at codespeak.net
Wed Feb 18 12:10:09 CET 2009
Author: hpk
Date: Wed Feb 18 12:10:07 2009
New Revision: 62001
Modified:
py/branch/pytestplugin/py/test/handleplugin.py
py/branch/pytestplugin/py/test/plugin/pytest_pocoo.py
py/branch/pytestplugin/py/test/plugin/pytest_pytester.py
py/branch/pytestplugin/py/test/plugin/pytest_unittest.py
py/branch/pytestplugin/py/test/testing/suptest.py
py/branch/pytestplugin/py/test/testing/test_handleplugin.py
py/branch/pytestplugin/py/test/testing/test_session.py
Log:
* avoid double-registry of plugins
* rename "parse_and_run" helper to "inline_run"
Modified: py/branch/pytestplugin/py/test/handleplugin.py
==============================================================================
--- py/branch/pytestplugin/py/test/handleplugin.py (original)
+++ py/branch/pytestplugin/py/test/handleplugin.py Wed Feb 18 12:10:07 2009
@@ -32,7 +32,7 @@
def import_plugin(self, spec):
if isinstance(spec, str):
modname, clsname = canonical_names(spec)
- if clsname not in self._plugins:
+ if clsname.lower() not in self._plugins:
mod = importplugin(modname)
plugin = registerplugin(self.pm.register, mod, clsname)
self._plugins[clsname.lower()] = plugin
@@ -88,6 +88,7 @@
# XXX old code to automatically load classes
#
def canonical_names(importspec):
+ importspec = importspec.lower()
modprefix = "pytest_"
if not importspec.startswith(modprefix):
importspec = modprefix + importspec
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 18 12:10:07 2009
@@ -58,7 +58,7 @@
old = Pocoo.getproxy
Pocoo.getproxy = MockProxy
try:
- result = fstester.parse_and_run(testpath, "--pocoo-sendfailures")
+ result = fstester.inline_run(testpath, "--pocoo-sendfailures")
finally:
Pocoo.getproxy = old
assert len(l) == 1
Modified: py/branch/pytestplugin/py/test/plugin/pytest_pytester.py
==============================================================================
--- py/branch/pytestplugin/py/test/plugin/pytest_pytester.py (original)
+++ py/branch/pytestplugin/py/test/plugin/pytest_pytester.py Wed Feb 18 12:10:07 2009
@@ -45,7 +45,7 @@
if not impname in self._plugins:
self._plugins.append(impname)
- def parse_and_run(self, *args):
+ def inline_run(self, *args):
config = self.parseconfig(*args)
config.pluginmanager.configure(config)
session = config.initsession()
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 18 12:10:07 2009
@@ -83,7 +83,7 @@
def test_failing(self):
self.assertEquals('foo', 'bar')
""")
- sorter = fstester.parse_and_run(testpath)
+ sorter = fstester.inline_run(testpath)
assert sorter.getreport("testpassing").passed
assert sorter.getreport("test_failing").failed
@@ -97,7 +97,7 @@
def test_setUp(self):
self.assertEquals(1, self.foo)
""")
- sorter = fstester.parse_and_run(testpath)
+ sorter = fstester.inline_run(testpath)
rep = sorter.getreport("test_setUp")
assert rep.passed
@@ -115,7 +115,7 @@
def test_check(self):
self.assertEquals(MyTestCase.l, [None])
""")
- sorter = fstester.parse_and_run(testpath)
+ sorter = fstester.inline_run(testpath)
passed, skipped, failed = sorter.countoutcomes()
assert passed + skipped + failed == 2
assert failed == 0, failed
Modified: py/branch/pytestplugin/py/test/testing/suptest.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/suptest.py (original)
+++ py/branch/pytestplugin/py/test/testing/suptest.py Wed Feb 18 12:10:07 2009
@@ -174,7 +174,7 @@
return runner(item, **runnerargs)
class InlineSession(InlineCollection):
- def parse_and_run(self, *args):
+ def inline_run(self, *args):
config = self.parseconfig(*args)
config.pluginmanager.configure(config)
session = config.initsession()
Modified: py/branch/pytestplugin/py/test/testing/test_handleplugin.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_handleplugin.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_handleplugin.py Wed Feb 18 12:10:07 2009
@@ -59,12 +59,10 @@
assert len(pseudoconfig.opts) == 1
def test_canonical_names():
- impname, clsname = canonical_names("xyz")
- assert impname == "pytest_xyz"
- assert clsname == "Xyz"
- impname, clsname = canonical_names("pytest_xyz")
- assert impname == "pytest_xyz"
- assert clsname == "Xyz"
+ for name in 'xyz', 'pytest_xyz', 'pytest_Xyz', 'Xyz':
+ impname, clsname = canonical_names(name)
+ assert impname == "pytest_xyz"
+ assert clsname == "Xyz"
def test_registerplugin():
l = []
@@ -77,7 +75,23 @@
assert importplugin("py") == py
py.test.raises(ImportError, "importplugin('laksjd.qwe')")
mod = importplugin("pytest_terminal")
- assert mod == py.__.test.plugin.pytest_terminal
+ assert mod is py.__.test.plugin.pytest_terminal
+
+class TestPluginManager:
+ def test_importplugin(self, fstester):
+ mod = py.std.new.module("x")
+ mod.pytest_plugins = "pytest_a"
+ aplugin = fstester.makepyfile(pytest_a="""class A: pass""")
+ pm = PytestPluginManager()
+ l = []
+ pm.pm._bus.subscribe(pluginregistered=l.append)
+ #syspath.prepend(aplugin.dirpath())
+ py.std.sys.path.insert(0, str(aplugin.dirpath()))
+ pm.consider_module(mod)
+ assert pm.getplugin('a').__class__.__name__ == "A"
+ assert len(l) == 1
+ pm.consider_module(mod)
+ assert len(l) == 1
import os, sys
Modified: py/branch/pytestplugin/py/test/testing/test_session.py
==============================================================================
--- py/branch/pytestplugin/py/test/testing/test_session.py (original)
+++ py/branch/pytestplugin/py/test/testing/test_session.py Wed Feb 18 12:10:07 2009
@@ -14,7 +14,7 @@
assert 42 == 43
""")
def check(keyword, name):
- sorter = self.parse_and_run("-s", "-k", keyword, file_test)
+ sorter = self.inline_run("-s", "-k", keyword, file_test)
passed, skipped, failed = sorter.listoutcomes()
assert len(failed) == 1
assert failed[0].colitem.name == name
@@ -56,7 +56,7 @@
def test_two(): assert 1
def test_three(): assert 1
""")
- sorter = self.parse_and_run("-k", "test_two:", threepass)
+ sorter = self.inline_run("-k", "test_two:", threepass)
passed, skipped, failed = sorter.listoutcomes()
assert len(passed) == 2
assert not failed
More information about the pytest-commit
mailing list