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
def test_conftestcutdir(pytester: Pytester) -> None: conf = pytester.makeconftest("") p = pytester.mkdir("x") conftest = PytestPluginManager() conftest_setinitial(conftest, [pytester.path], confcutdir=p) values = conftest._getconftestmodules(p, importmode="prepend", rootpath=pytester.path) assert len(values) == 0 values = conftest._getconftestmodules(conf.parent, importmode="prepend", rootpath=pytester.path) assert len(values) == 0 assert not conftest.has_plugin(str(conf)) # but we can still import a conftest directly conftest._importconftest(conf, importmode="prepend", rootpath=pytester.path) values = conftest._getconftestmodules(conf.parent, importmode="prepend", rootpath=pytester.path) assert values[0].__file__ is not None assert values[0].__file__.startswith(str(conf)) # and all sub paths get updated properly values = conftest._getconftestmodules(p, importmode="prepend", rootpath=pytester.path) assert len(values) == 1 assert values[0].__file__ is not None assert values[0].__file__.startswith(str(conf))
def test_blocked_plugin_can_be_used(self, pytestpm: PytestPluginManager) -> None: pytestpm.consider_preparse(["xyz", "-p", "no:abc", "-p", "abc"]) assert pytestpm.has_plugin("abc") assert not pytestpm.is_blocked("abc") assert not pytestpm.is_blocked("pytest_abc")