コード例 #1
0
 def test_plugin_prevent_register(self, pytestpm: PytestPluginManager) -> None:
     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
コード例 #2
0
 def test_plugin_prevent_register_unregistered_alredy_registered(
         self, pytestpm: PytestPluginManager) -> None:
     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
コード例 #3
0
 def test_register_imported_modules(self):
     pm = PytestPluginManager()
     mod = py.std.types.ModuleType("x.y.pytest_hello")
     pm.register(mod)
     assert pm.is_registered(mod)
     values = pm.get_plugins()
     assert mod in values
     pytest.raises(ValueError, "pm.register(mod)")
     pytest.raises(ValueError, lambda: pm.register(mod))
     # assert not pm.is_registered(mod2)
     assert pm.get_plugins() == values
コード例 #4
0
ファイル: test_conftest.py プロジェクト: SalmonMode/pytest
def test_setinitial_conftest_subdirs(pytester: Pytester, name: str) -> None:
    sub = pytester.mkdir(name)
    subconftest = sub.joinpath("conftest.py")
    subconftest.touch()
    pm = PytestPluginManager()
    conftest_setinitial(pm, [sub.parent], confcutdir=pytester.path)
    key = subconftest.resolve()
    if name not in ("whatever", ".dotdir"):
        assert pm.has_plugin(str(key))
        assert len(set(pm.get_plugins()) - {pm}) == 1
    else:
        assert not pm.has_plugin(str(key))
        assert len(set(pm.get_plugins()) - {pm}) == 0
コード例 #5
0
    def test_plugin_prevent_register_stepwise_on_cacheprovider_unregister(
            self, pytestpm: PytestPluginManager) -> None:
        """From PR #4304: The only way to unregister a module is documented at
        the end of https://docs.pytest.org/en/stable/plugins.html.

        When unregister cacheprovider, then unregister stepwise too.
        """
        pytestpm.register(42, name="cacheprovider")
        pytestpm.register(43, name="stepwise")
        l1 = pytestpm.get_plugins()
        assert 42 in l1
        assert 43 in l1
        pytestpm.consider_preparse(["xyz", "-p", "no:cacheprovider"])
        l2 = pytestpm.get_plugins()
        assert 42 not in l2
        assert 43 not in l2
コード例 #6
0
    def test_import_plugin_importname(self, pytester: Pytester,
                                      pytestpm: PytestPluginManager) -> None:
        pytest.raises(ImportError, pytestpm.import_plugin, "qweqwex.y")
        pytest.raises(ImportError, pytestpm.import_plugin, "pytest_qweqwx.y")

        pytester.syspathinsert()
        pluginname = "pytest_hello"
        pytester.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")
        assert plugin1.__name__.endswith("pytest_hello")
        plugin2 = pytestpm.get_plugin("pytest_hello")
        assert plugin2 is plugin1
コード例 #7
0
 def test_consider_env_plugin_instantiation(
     self,
     pytester: Pytester,
     monkeypatch: MonkeyPatch,
     pytestpm: PytestPluginManager,
 ) -> None:
     pytester.syspathinsert()
     pytester.makepyfile(xy123="#")
     monkeypatch.setitem(os.environ, "PYTEST_PLUGINS", "xy123")
     l1 = len(pytestpm.get_plugins())
     pytestpm.consider_env()
     l2 = len(pytestpm.get_plugins())
     assert l2 == l1 + 1
     assert pytestpm.get_plugin("xy123")
     pytestpm.consider_env()
     l3 = len(pytestpm.get_plugins())
     assert l2 == l3
コード例 #8
0
ファイル: test_conftest.py プロジェクト: SalmonMode/pytest
def test_issue151_load_all_conftests(pytester: Pytester) -> None:
    names = "code proj src".split()
    for name in names:
        p = pytester.mkdir(name)
        p.joinpath("conftest.py").touch()

    pm = PytestPluginManager()
    conftest_setinitial(pm, names)
    assert len(set(pm.get_plugins()) - {pm}) == len(names)