2016-10-13 04:46:47 +08:00
|
|
|
# encoding: UTF-8
|
2017-03-17 09:21:30 +08:00
|
|
|
from __future__ import absolute_import, division, print_function
|
2015-04-29 22:40:51 +08:00
|
|
|
import pytest
|
|
|
|
import os
|
2017-12-27 11:47:26 +08:00
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import types
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
from _pytest.config import get_config, PytestPluginManager
|
2016-11-21 22:50:21 +08:00
|
|
|
from _pytest.main import EXIT_NOTESTSCOLLECTED, Session
|
|
|
|
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
@pytest.fixture
|
|
|
|
def pytestpm():
|
|
|
|
return PytestPluginManager()
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestPytestPluginInteractions(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2015-04-29 22:40:51 +08:00
|
|
|
def test_addhooks_conftestplugin(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
newhooks="""
|
2015-04-29 22:40:51 +08:00
|
|
|
def pytest_myhook(xyz):
|
|
|
|
"new hook"
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
conf = testdir.makeconftest(
|
|
|
|
"""
|
2015-04-29 22:40:51 +08:00
|
|
|
import sys ; sys.path.insert(0, '.')
|
|
|
|
import newhooks
|
|
|
|
def pytest_addhooks(pluginmanager):
|
|
|
|
pluginmanager.addhooks(newhooks)
|
|
|
|
def pytest_myhook(xyz):
|
|
|
|
return xyz + 1
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
config = get_config()
|
|
|
|
pm = config.pluginmanager
|
|
|
|
pm.hook.pytest_addhooks.call_historic(
|
2018-05-23 22:48:46 +08:00
|
|
|
kwargs=dict(pluginmanager=config.pluginmanager)
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
config.pluginmanager._importconftest(conf)
|
2017-07-17 07:25:09 +08:00
|
|
|
# print(config.pluginmanager.get_plugins())
|
2015-04-29 22:40:51 +08:00
|
|
|
res = config.hook.pytest_myhook(xyz=10)
|
|
|
|
assert res == [11]
|
|
|
|
|
|
|
|
def test_addhooks_nohooks(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2015-04-29 22:40:51 +08:00
|
|
|
import sys
|
|
|
|
def pytest_addhooks(pluginmanager):
|
|
|
|
pluginmanager.addhooks(sys)
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
res = testdir.runpytest()
|
|
|
|
assert res.ret != 0
|
2018-05-23 22:48:46 +08:00
|
|
|
res.stderr.fnmatch_lines(["*did not find*sys*"])
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
def test_namespace_early_from_import(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
p = testdir.makepyfile(
|
|
|
|
"""
|
2015-04-29 22:40:51 +08:00
|
|
|
from pytest import Item
|
|
|
|
from pytest import Item as Item2
|
|
|
|
assert Item is Item2
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
result = testdir.runpython(p)
|
|
|
|
assert result.ret == 0
|
|
|
|
|
|
|
|
def test_do_ext_namespace(self, testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makeconftest(
|
|
|
|
"""
|
2015-04-29 22:40:51 +08:00
|
|
|
def pytest_namespace():
|
|
|
|
return {'hello': 'world'}
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
p = testdir.makepyfile(
|
|
|
|
"""
|
2015-04-29 22:40:51 +08:00
|
|
|
from pytest import hello
|
|
|
|
import pytest
|
|
|
|
def test_hello():
|
|
|
|
assert hello == "world"
|
|
|
|
assert 'hello' in pytest.__all__
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
reprec = testdir.inline_run(p)
|
|
|
|
reprec.assertoutcome(passed=1)
|
|
|
|
|
|
|
|
def test_do_option_postinitialize(self, testdir):
|
|
|
|
config = testdir.parseconfigure()
|
2018-05-23 22:48:46 +08:00
|
|
|
assert not hasattr(config.option, "test123")
|
|
|
|
p = testdir.makepyfile(
|
|
|
|
"""
|
2015-04-29 22:40:51 +08:00
|
|
|
def pytest_addoption(parser):
|
|
|
|
parser.addoption('--test123', action="store_true",
|
|
|
|
default=True)
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
config.pluginmanager._importconftest(p)
|
|
|
|
assert config.option.test123
|
|
|
|
|
|
|
|
def test_configure(self, testdir):
|
|
|
|
config = testdir.parseconfig()
|
2017-11-04 23:17:20 +08:00
|
|
|
values = []
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class A(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2015-04-29 22:40:51 +08:00
|
|
|
def pytest_configure(self, config):
|
2017-11-04 23:17:20 +08:00
|
|
|
values.append(self)
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
config.pluginmanager.register(A())
|
2017-11-04 23:17:20 +08:00
|
|
|
assert len(values) == 0
|
2015-04-29 22:40:51 +08:00
|
|
|
config._do_configure()
|
2017-11-04 23:17:20 +08:00
|
|
|
assert len(values) == 1
|
2015-04-29 22:40:51 +08:00
|
|
|
config.pluginmanager.register(A()) # leads to a configured() plugin
|
2017-11-04 23:17:20 +08:00
|
|
|
assert len(values) == 2
|
|
|
|
assert values[0] != values[1]
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
config._ensure_unconfigure()
|
|
|
|
config.pluginmanager.register(A())
|
2017-11-04 23:17:20 +08:00
|
|
|
assert len(values) == 2
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
def test_hook_tracing(self):
|
|
|
|
pytestpm = get_config().pluginmanager # fully initialized with plugins
|
|
|
|
saveindent = []
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class api1(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2015-04-29 22:40:51 +08:00
|
|
|
def pytest_plugin_registered(self):
|
|
|
|
saveindent.append(pytestpm.trace.root.indent)
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class api2(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2015-04-29 22:40:51 +08:00
|
|
|
def pytest_plugin_registered(self):
|
|
|
|
saveindent.append(pytestpm.trace.root.indent)
|
|
|
|
raise ValueError()
|
2016-11-21 04:59:15 +08:00
|
|
|
|
2017-11-04 23:17:20 +08:00
|
|
|
values = []
|
|
|
|
pytestpm.trace.root.setwriter(values.append)
|
2015-04-29 22:40:51 +08:00
|
|
|
undo = pytestpm.enable_tracing()
|
|
|
|
try:
|
|
|
|
indent = pytestpm.trace.root.indent
|
|
|
|
p = api1()
|
|
|
|
pytestpm.register(p)
|
|
|
|
assert pytestpm.trace.root.indent == indent
|
2017-11-04 23:17:20 +08:00
|
|
|
assert len(values) >= 2
|
2018-05-23 22:48:46 +08:00
|
|
|
assert "pytest_plugin_registered" in values[0]
|
|
|
|
assert "finish" in values[1]
|
2015-04-29 22:40:51 +08:00
|
|
|
|
2017-11-04 23:17:20 +08:00
|
|
|
values[:] = []
|
2015-04-29 22:40:51 +08:00
|
|
|
with pytest.raises(ValueError):
|
|
|
|
pytestpm.register(api2())
|
|
|
|
assert pytestpm.trace.root.indent == indent
|
|
|
|
assert saveindent[0] > indent
|
|
|
|
finally:
|
|
|
|
undo()
|
|
|
|
|
2016-11-21 22:50:21 +08:00
|
|
|
def test_hook_proxy(self, testdir):
|
|
|
|
"""Test the gethookproxy function(#2016)"""
|
|
|
|
config = testdir.parseconfig()
|
|
|
|
session = Session(config)
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(**{"tests/conftest.py": "", "tests/subdir/conftest.py": ""})
|
2016-11-21 22:50:21 +08:00
|
|
|
|
2018-05-23 22:48:46 +08:00
|
|
|
conftest1 = testdir.tmpdir.join("tests/conftest.py")
|
|
|
|
conftest2 = testdir.tmpdir.join("tests/subdir/conftest.py")
|
2016-11-21 22:50:21 +08:00
|
|
|
|
|
|
|
config.pluginmanager._importconftest(conftest1)
|
2018-05-23 22:48:46 +08:00
|
|
|
ihook_a = session.gethookproxy(testdir.tmpdir.join("tests"))
|
2016-11-21 22:50:21 +08:00
|
|
|
assert ihook_a is not None
|
|
|
|
config.pluginmanager._importconftest(conftest2)
|
2018-05-23 22:48:46 +08:00
|
|
|
ihook_b = session.gethookproxy(testdir.tmpdir.join("tests"))
|
2016-11-21 22:50:21 +08:00
|
|
|
assert ihook_a is not ihook_b
|
|
|
|
|
2015-09-29 00:05:58 +08:00
|
|
|
def test_warn_on_deprecated_addhooks(self, pytestpm):
|
|
|
|
warnings = []
|
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class get_warnings(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2015-09-29 00:05:58 +08:00
|
|
|
def pytest_logwarning(self, code, fslocation, message, nodeid):
|
|
|
|
warnings.append(message)
|
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class Plugin(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2015-09-29 00:05:58 +08:00
|
|
|
def pytest_testhook():
|
|
|
|
pass
|
|
|
|
|
|
|
|
pytestpm.register(get_warnings())
|
|
|
|
before = list(warnings)
|
|
|
|
pytestpm.addhooks(Plugin())
|
|
|
|
assert len(warnings) == len(before) + 1
|
|
|
|
assert "deprecated" in warnings[-1]
|
|
|
|
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
def test_namespace_has_default_and_env_plugins(testdir):
|
2018-05-23 22:48:46 +08:00
|
|
|
p = testdir.makepyfile(
|
|
|
|
"""
|
2015-04-29 22:40:51 +08:00
|
|
|
import pytest
|
|
|
|
pytest.mark
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
result = testdir.runpython(p)
|
|
|
|
assert result.ret == 0
|
|
|
|
|
2017-07-17 07:25:09 +08:00
|
|
|
|
2015-04-29 22:40:51 +08:00
|
|
|
def test_default_markers(testdir):
|
|
|
|
result = testdir.runpytest("--markers")
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(["*tryfirst*first*", "*trylast*last*"])
|
2015-04-29 22:40:51 +08:00
|
|
|
|
2016-03-09 06:18:13 +08:00
|
|
|
|
2016-10-13 04:46:47 +08:00
|
|
|
def test_importplugin_error_message(testdir, pytestpm):
|
2016-03-09 06:18:13 +08:00
|
|
|
"""Don't hide import errors when importing plugins and provide
|
|
|
|
an easy to debug message.
|
2016-10-13 04:46:47 +08:00
|
|
|
|
|
|
|
See #375 and #1998.
|
2016-03-09 06:18:13 +08:00
|
|
|
"""
|
2015-04-29 22:40:51 +08:00
|
|
|
testdir.syspathinsert(testdir.tmpdir)
|
2018-05-23 22:48:46 +08:00
|
|
|
testdir.makepyfile(
|
|
|
|
qwe="""
|
2016-10-13 04:46:47 +08:00
|
|
|
# encoding: UTF-8
|
2017-09-19 20:23:07 +08:00
|
|
|
def test_traceback():
|
|
|
|
raise ImportError(u'Not possible to import: ☺')
|
|
|
|
test_traceback()
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
with pytest.raises(ImportError) as excinfo:
|
|
|
|
pytestpm.import_plugin("qwe")
|
2017-09-19 20:23:07 +08:00
|
|
|
|
|
|
|
expected_message = '.*Error importing plugin "qwe": Not possible to import: .'
|
|
|
|
expected_traceback = ".*in test_traceback"
|
2017-12-27 11:47:26 +08:00
|
|
|
assert re.match(expected_message, str(excinfo.value))
|
|
|
|
assert re.match(expected_traceback, str(excinfo.traceback[-1]))
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestPytestPluginManager(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2015-04-29 22:40:51 +08:00
|
|
|
def test_register_imported_modules(self):
|
|
|
|
pm = PytestPluginManager()
|
2017-12-27 11:47:26 +08:00
|
|
|
mod = types.ModuleType("x.y.pytest_hello")
|
2015-04-29 22:40:51 +08:00
|
|
|
pm.register(mod)
|
|
|
|
assert pm.is_registered(mod)
|
2017-11-04 23:17:20 +08:00
|
|
|
values = pm.get_plugins()
|
|
|
|
assert mod in values
|
2015-04-29 22:40:51 +08:00
|
|
|
pytest.raises(ValueError, "pm.register(mod)")
|
|
|
|
pytest.raises(ValueError, lambda: pm.register(mod))
|
2017-07-17 07:25:09 +08:00
|
|
|
# assert not pm.is_registered(mod2)
|
2017-11-04 23:17:20 +08:00
|
|
|
assert pm.get_plugins() == values
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
def test_canonical_import(self, monkeypatch):
|
2017-12-27 11:47:26 +08:00
|
|
|
mod = types.ModuleType("pytest_xyz")
|
2018-05-23 22:48:46 +08:00
|
|
|
monkeypatch.setitem(sys.modules, "pytest_xyz", mod)
|
2015-04-29 22:40:51 +08:00
|
|
|
pm = PytestPluginManager()
|
2018-05-23 22:48:46 +08:00
|
|
|
pm.import_plugin("pytest_xyz")
|
|
|
|
assert pm.get_plugin("pytest_xyz") == mod
|
2015-04-29 22:40:51 +08:00
|
|
|
assert pm.is_registered(mod)
|
|
|
|
|
|
|
|
def test_consider_module(self, testdir, pytestpm):
|
|
|
|
testdir.syspathinsert()
|
|
|
|
testdir.makepyfile(pytest_p1="#")
|
|
|
|
testdir.makepyfile(pytest_p2="#")
|
2017-12-27 11:47:26 +08:00
|
|
|
mod = types.ModuleType("temp")
|
2015-04-29 22:40:51 +08:00
|
|
|
mod.pytest_plugins = ["pytest_p1", "pytest_p2"]
|
|
|
|
pytestpm.consider_module(mod)
|
|
|
|
assert pytestpm.get_plugin("pytest_p1").__name__ == "pytest_p1"
|
|
|
|
assert pytestpm.get_plugin("pytest_p2").__name__ == "pytest_p2"
|
|
|
|
|
|
|
|
def test_consider_module_import_module(self, testdir):
|
|
|
|
pytestpm = get_config().pluginmanager
|
2017-12-27 11:47:26 +08:00
|
|
|
mod = types.ModuleType("x")
|
2015-04-29 22:40:51 +08:00
|
|
|
mod.pytest_plugins = "pytest_a"
|
|
|
|
aplugin = testdir.makepyfile(pytest_a="#")
|
|
|
|
reprec = testdir.make_hook_recorder(pytestpm)
|
2017-07-17 07:25:09 +08:00
|
|
|
# syspath.prepend(aplugin.dirpath())
|
2017-12-27 11:47:26 +08:00
|
|
|
sys.path.insert(0, str(aplugin.dirpath()))
|
2015-04-29 22:40:51 +08:00
|
|
|
pytestpm.consider_module(mod)
|
|
|
|
call = reprec.getcall(pytestpm.hook.pytest_plugin_registered.name)
|
|
|
|
assert call.plugin.__name__ == "pytest_a"
|
|
|
|
|
|
|
|
# check that it is not registered twice
|
|
|
|
pytestpm.consider_module(mod)
|
2017-11-04 23:17:20 +08:00
|
|
|
values = reprec.getcalls("pytest_plugin_registered")
|
|
|
|
assert len(values) == 1
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
def test_consider_env_fails_to_import(self, monkeypatch, pytestpm):
|
2018-05-23 22:48:46 +08:00
|
|
|
monkeypatch.setenv("PYTEST_PLUGINS", "nonexisting", prepend=",")
|
2015-04-29 22:40:51 +08:00
|
|
|
with pytest.raises(ImportError):
|
|
|
|
pytestpm.consider_env()
|
|
|
|
|
|
|
|
def test_plugin_skip(self, testdir, monkeypatch):
|
2018-05-23 22:48:46 +08:00
|
|
|
p = testdir.makepyfile(
|
|
|
|
skipping1="""
|
2015-04-29 22:40:51 +08:00
|
|
|
import pytest
|
|
|
|
pytest.skip("hello")
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
p.copy(p.dirpath("skipping2.py"))
|
|
|
|
monkeypatch.setenv("PYTEST_PLUGINS", "skipping2")
|
|
|
|
result = testdir.runpytest("-rw", "-p", "skipping1", syspathinsert=True)
|
2015-07-05 01:42:22 +08:00
|
|
|
assert result.ret == EXIT_NOTESTSCOLLECTED
|
2018-05-23 22:48:46 +08:00
|
|
|
result.stdout.fnmatch_lines(
|
|
|
|
["*skipped plugin*skipping1*hello*", "*skipped plugin*skipping2*hello*"]
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
def test_consider_env_plugin_instantiation(self, testdir, monkeypatch, pytestpm):
|
|
|
|
testdir.syspathinsert()
|
|
|
|
testdir.makepyfile(xy123="#")
|
2018-05-23 22:48:46 +08:00
|
|
|
monkeypatch.setitem(os.environ, "PYTEST_PLUGINS", "xy123")
|
2015-04-29 22:40:51 +08:00
|
|
|
l1 = len(pytestpm.get_plugins())
|
|
|
|
pytestpm.consider_env()
|
|
|
|
l2 = len(pytestpm.get_plugins())
|
|
|
|
assert l2 == l1 + 1
|
2018-05-23 22:48:46 +08:00
|
|
|
assert pytestpm.get_plugin("xy123")
|
2015-04-29 22:40:51 +08:00
|
|
|
pytestpm.consider_env()
|
|
|
|
l3 = len(pytestpm.get_plugins())
|
|
|
|
assert l2 == l3
|
|
|
|
|
|
|
|
def test_pluginmanager_ENV_startup(self, testdir, monkeypatch):
|
|
|
|
testdir.makepyfile(pytest_x500="#")
|
2018-05-23 22:48:46 +08:00
|
|
|
p = testdir.makepyfile(
|
|
|
|
"""
|
2015-04-29 22:40:51 +08:00
|
|
|
import pytest
|
|
|
|
def test_hello(pytestconfig):
|
|
|
|
plugin = pytestconfig.pluginmanager.get_plugin('pytest_x500')
|
|
|
|
assert plugin is not None
|
2018-05-23 22:48:46 +08:00
|
|
|
"""
|
|
|
|
)
|
|
|
|
monkeypatch.setenv("PYTEST_PLUGINS", "pytest_x500", prepend=",")
|
2015-04-29 22:40:51 +08:00
|
|
|
result = testdir.runpytest(p, syspathinsert=True)
|
|
|
|
assert result.ret == 0
|
|
|
|
result.stdout.fnmatch_lines(["*1 passed*"])
|
|
|
|
|
|
|
|
def test_import_plugin_importname(self, testdir, pytestpm):
|
|
|
|
pytest.raises(ImportError, 'pytestpm.import_plugin("qweqwex.y")')
|
|
|
|
pytest.raises(ImportError, 'pytestpm.import_plugin("pytest_qweqwx.y")')
|
|
|
|
|
|
|
|
testdir.syspathinsert()
|
|
|
|
pluginname = "pytest_hello"
|
|
|
|
testdir.makepyfile(**{pluginname: ""})
|
|
|
|
pytestpm.import_plugin("pytest_hello")
|
|
|
|
len1 = len(pytestpm.get_plugins())
|
|
|
|
pytestpm.import_plugin("pytest_hello")
|
|
|
|
len2 = len(pytestpm.get_plugins())
|
|
|
|
assert len1 == len2
|
|
|
|
plugin1 = pytestpm.get_plugin("pytest_hello")
|
2018-05-23 22:48:46 +08:00
|
|
|
assert plugin1.__name__.endswith("pytest_hello")
|
2015-04-29 22:40:51 +08:00
|
|
|
plugin2 = pytestpm.get_plugin("pytest_hello")
|
|
|
|
assert plugin2 is plugin1
|
|
|
|
|
|
|
|
def test_import_plugin_dotted_name(self, testdir, pytestpm):
|
|
|
|
pytest.raises(ImportError, 'pytestpm.import_plugin("qweqwex.y")')
|
|
|
|
pytest.raises(ImportError, 'pytestpm.import_plugin("pytest_qweqwex.y")')
|
|
|
|
|
|
|
|
testdir.syspathinsert()
|
|
|
|
testdir.mkpydir("pkg").join("plug.py").write("x=3")
|
|
|
|
pluginname = "pkg.plug"
|
|
|
|
pytestpm.import_plugin(pluginname)
|
|
|
|
mod = pytestpm.get_plugin("pkg.plug")
|
|
|
|
assert mod.x == 3
|
|
|
|
|
|
|
|
def test_consider_conftest_deps(self, testdir, pytestpm):
|
|
|
|
mod = testdir.makepyfile("pytest_plugins='xyz'").pyimport()
|
|
|
|
with pytest.raises(ImportError):
|
|
|
|
pytestpm.consider_conftest(mod)
|
|
|
|
|
|
|
|
|
2017-02-17 02:41:51 +08:00
|
|
|
class TestPytestPluginManagerBootstrapming(object):
|
2018-05-23 22:48:46 +08:00
|
|
|
|
2015-04-29 22:40:51 +08:00
|
|
|
def test_preparse_args(self, pytestpm):
|
2018-05-23 22:48:46 +08:00
|
|
|
pytest.raises(
|
|
|
|
ImportError, lambda: pytestpm.consider_preparse(["xyz", "-p", "hello123"])
|
|
|
|
)
|
2015-04-29 22:40:51 +08:00
|
|
|
|
|
|
|
def test_plugin_prevent_register(self, pytestpm):
|
|
|
|
pytestpm.consider_preparse(["xyz", "-p", "no:abc"])
|
|
|
|
l1 = pytestpm.get_plugins()
|
|
|
|
pytestpm.register(42, name="abc")
|
|
|
|
l2 = pytestpm.get_plugins()
|
|
|
|
assert len(l2) == len(l1)
|
|
|
|
assert 42 not in l2
|
|
|
|
|
|
|
|
def test_plugin_prevent_register_unregistered_alredy_registered(self, pytestpm):
|
|
|
|
pytestpm.register(42, name="abc")
|
|
|
|
l1 = pytestpm.get_plugins()
|
|
|
|
assert 42 in l1
|
|
|
|
pytestpm.consider_preparse(["xyz", "-p", "no:abc"])
|
|
|
|
l2 = pytestpm.get_plugins()
|
|
|
|
assert 42 not in l2
|