streamline and document handling of builtin module special casing.
--HG-- branch : plugin_no_pytest
This commit is contained in:
parent
8fde2f98ae
commit
95dd2eb1da
|
@ -53,6 +53,10 @@ default_plugins = (
|
|||
"tmpdir monkeypatch recwarn pastebin helpconfig nose assertion genscript "
|
||||
"junitxml resultlog doctest").split()
|
||||
|
||||
builtin_plugins = set(default_plugins)
|
||||
builtin_plugins.add("pytester")
|
||||
|
||||
|
||||
def _preloadplugins():
|
||||
assert not _preinit
|
||||
_preinit.append(get_plugin_manager())
|
||||
|
@ -131,14 +135,6 @@ class PytestPluginManager(PluginManager):
|
|||
except ValueError:
|
||||
pass
|
||||
|
||||
def getplugin(self, name):
|
||||
if name is None:
|
||||
return name
|
||||
plugin = super(PytestPluginManager, self).getplugin(name)
|
||||
if plugin is None:
|
||||
plugin = super(PytestPluginManager, self).getplugin("_pytest." + name)
|
||||
return plugin
|
||||
|
||||
def pytest_configure(self, config):
|
||||
config.addinivalue_line("markers",
|
||||
"tryfirst: mark a hook implementation function such that the "
|
||||
|
@ -294,11 +290,19 @@ class PytestPluginManager(PluginManager):
|
|||
self.import_plugin(spec)
|
||||
|
||||
def import_plugin(self, modname):
|
||||
# most often modname refers to builtin modules, e.g. "pytester",
|
||||
# "terminal" or "capture". Those plugins are registered under their
|
||||
# basename for historic purposes but must be imported with the
|
||||
# _pytest prefix.
|
||||
assert isinstance(modname, str)
|
||||
if self.getplugin(modname) is not None:
|
||||
return
|
||||
if modname in builtin_plugins:
|
||||
importspec = "_pytest." + modname
|
||||
else:
|
||||
importspec = modname
|
||||
try:
|
||||
mod = importplugin(modname)
|
||||
__import__(importspec)
|
||||
except ImportError:
|
||||
raise
|
||||
except Exception as e:
|
||||
|
@ -307,6 +311,7 @@ class PytestPluginManager(PluginManager):
|
|||
raise
|
||||
self._warnings.append("skipped plugin %r: %s" %((modname, e.msg)))
|
||||
else:
|
||||
mod = sys.modules[importspec]
|
||||
self.register(mod, modname)
|
||||
self.consider_module(mod)
|
||||
|
||||
|
@ -1040,14 +1045,3 @@ def setns(obj, dic):
|
|||
# pytest.__all__.append(name)
|
||||
setattr(pytest, name, value)
|
||||
|
||||
|
||||
def importplugin(importspec):
|
||||
name = importspec
|
||||
try:
|
||||
mod = "_pytest." + name
|
||||
__import__(mod)
|
||||
return sys.modules[mod]
|
||||
except ImportError:
|
||||
__import__(importspec)
|
||||
return sys.modules[importspec]
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import pytest, py, os
|
||||
from _pytest.core import * # noqa
|
||||
from _pytest.config import get_plugin_manager, importplugin
|
||||
from _pytest.config import get_plugin_manager
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
@ -590,10 +590,11 @@ def test_default_markers(testdir):
|
|||
"*trylast*last*",
|
||||
])
|
||||
|
||||
def test_importplugin_issue375(testdir):
|
||||
def test_importplugin_issue375(testdir, pytestpm):
|
||||
testdir.syspathinsert(testdir.tmpdir)
|
||||
testdir.makepyfile(qwe="import aaaa")
|
||||
excinfo = pytest.raises(ImportError, lambda: importplugin("qwe"))
|
||||
with pytest.raises(ImportError) as excinfo:
|
||||
pytestpm.import_plugin("qwe")
|
||||
assert "qwe" not in str(excinfo.value)
|
||||
assert "aaaa" in str(excinfo.value)
|
||||
|
||||
|
|
Loading…
Reference in New Issue