# HG changeset patch -- Bitbucket.org # Project pytest # URL http://bitbucket.org/hpk42/pytest/overview # User holger krekel <hol...@merlinux.eu> # Date 1288548106 -3600 # Node ID f0ca0f882f802bb0bbfb3a9dd49d224b5f88cf55 # Parent c628ad6a63cd736186b7724e9ac580f05316fb3e allow modules/conftest files specify dotted import paths for loading plugins
--- a/doc/customize.txt +++ b/doc/customize.txt @@ -128,15 +128,19 @@ py.test loads plugin modules at tool sta * by recursively loading all plugins specified by the ``pytest_plugins`` variable in ``conftest.py`` files -Requiring/Loading plugins in a test module or plugin +Requiring/Loading plugins in a test module or conftest file ------------------------------------------------------------- -You can require plugins in a test module or a plugin like this:: +You can require plugins in a test module or a conftest file like this:: pytest_plugins = "name1", "name2", -When the test module or plugin is loaded the specified plugins -will be loaded. +When the test module or conftest plugin is loaded the specified plugins +will be loaded as well. You can also use dotted path like this:: + + pytest_plugins = "myapp.testsupport.myplugin" + +which will import the specified module as a py.test plugin. .. _`setuptools entry points`: .. _registered: --- a/pytest/_core.py +++ b/pytest/_core.py @@ -218,15 +218,16 @@ class PluginManager(object): kwargs=kwargs, firstresult=True).execute() def canonical_importname(name): + if '.' in name: + return name name = name.lower() if not name.startswith(IMPORTPREFIX): name = IMPORTPREFIX + name return name def importplugin(importspec): - #print "importing", importspec try: - return __import__(importspec) + return __import__(importspec, None, None, '__doc__') except ImportError: e = py.std.sys.exc_info()[1] if str(e).find(importspec) == -1: @@ -241,7 +242,7 @@ def importplugin(importspec): if str(e).find(name) == -1: raise # show the original exception, not the failing internal one - return __import__(importspec) + return __import__(importspec, None, None, '__doc__') class MultiCall: --- a/testing/test_pluginmanager.py +++ b/testing/test_pluginmanager.py @@ -101,6 +101,18 @@ class TestBootstrapping: plugin2 = pluginmanager.getplugin("hello") assert plugin2 is plugin1 + def test_import_plugin_dotted_name(self, testdir): + pluginmanager = PluginManager() + py.test.raises(ImportError, 'pluginmanager.import_plugin("x.y")') + py.test.raises(ImportError, 'pluginmanager.import_plugin("pytest_x.y")') + + reset = testdir.syspathinsert() + testdir.mkpydir("pkg").join("plug.py").write("x=3") + pluginname = "pkg.plug" + pluginmanager.import_plugin(pluginname) + mod = pluginmanager.getplugin("pkg.plug") + assert mod.x == 3 + def test_consider_module(self, testdir): pluginmanager = PluginManager() testdir.syspathinsert() _______________________________________________ py-svn mailing list py-svn@codespeak.net http://codespeak.net/mailman/listinfo/py-svn