Example #1
0
def test_doubledash_considered(testdir):
    conf = testdir.mkdir("--option")
    conf.ensure("conftest.py")
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [conf.basename, conf.basename])
    values = conftest._getconftestmodules(conf)
    assert len(values) == 1
Example #2
0
 def test_canonical_import(self, monkeypatch):
     mod = py.std.types.ModuleType("pytest_xyz")
     monkeypatch.setitem(py.std.sys.modules, 'pytest_xyz', mod)
     pm = PytestPluginManager()
     pm.import_plugin('pytest_xyz')
     assert pm.get_plugin('pytest_xyz') == mod
     assert pm.is_registered(mod)
Example #3
0
def test_conftestcutdir_inplace_considered(testdir):
    conf = testdir.makeconftest("")
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [conf.dirpath()], confcutdir=conf.dirpath())
    values = conftest._getconftestmodules(conf.dirpath())
    assert len(values) == 1
    assert values[0].__file__.startswith(str(conf))
Example #4
0
def test_conftest_import_order(testdir, monkeypatch):
    ct1 = testdir.makeconftest("")
    sub = testdir.mkdir("sub")
    ct2 = sub.join("conftest.py")
    ct2.write("")
    def impct(p):
        return p
    conftest = PytestPluginManager()
    monkeypatch.setattr(conftest, '_importconftest', impct)
    assert conftest._getconftestmodules(sub) == [ct1, ct2]
Example #5
0
def test_hookrecorder_basic(holder):
    pm = PytestPluginManager()
    pm.add_hookspecs(holder)
    rec = HookRecorder(pm)
    pm.hook.pytest_xyz(arg=123)
    call = rec.popcall("pytest_xyz")
    assert call.arg == 123
    assert call._name == "pytest_xyz"
    pytest.raises(pytest.fail.Exception, rec.popcall, "abc")
    pm.hook.pytest_xyz_noarg()
    call = rec.popcall("pytest_xyz_noarg")
    assert call._name == "pytest_xyz_noarg"
Example #6
0
 def test_immediate_initialiation_and_incremental_are_the_same(self, basedir):
     conftest = PytestPluginManager()
     len(conftest._path2confmods)
     conftest._getconftestmodules(basedir)
     snap1 = len(conftest._path2confmods)
     # assert len(conftest._path2confmods) == snap1 + 1
     conftest._getconftestmodules(basedir.join("adir"))
     assert len(conftest._path2confmods) == snap1 + 1
     conftest._getconftestmodules(basedir.join("b"))
     assert len(conftest._path2confmods) == snap1 + 2
Example #7
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
Example #8
0
def test_conftestcutdir(testdir):
    conf = testdir.makeconftest("")
    p = testdir.mkdir("x")
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [testdir.tmpdir], confcutdir=p)
    values = conftest._getconftestmodules(p)
    assert len(values) == 0
    values = conftest._getconftestmodules(conf.dirpath())
    assert len(values) == 0
    assert conf not in conftest._conftestpath2mod
    # but we can still import a conftest directly
    conftest._importconftest(conf)
    values = conftest._getconftestmodules(conf.dirpath())
    assert values[0].__file__.startswith(str(conf))
    # and all sub paths get updated properly
    values = conftest._getconftestmodules(p)
    assert len(values) == 1
    assert values[0].__file__.startswith(str(conf))
Example #9
0
 def test_basic_init(self, basedir):
     conftest = PytestPluginManager()
     p = basedir.join("adir")
     assert conftest._rget_with_confmod("a", p)[1] == 1
Example #10
0
 def test_basic_init(self, basedir):
     conftest = PytestPluginManager()
     p = basedir.join("adir")
     assert conftest._rget_with_confmod("a", p,
                                        importmode="prepend")[1] == 1
def pytestpm():
    return PytestPluginManager()
Example #12
0
def ConftestWithSetinitial(path):
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [path])
    return conftest
Example #13
0
 def test_configure_some(self):
     config = ctype(otype("somefile", 1), PytestPluginManager())
     pytest_configure(config)
     pytest_unconfigure(config)
Example #14
0
 def test_configure_none(self):
     config = ctype(otype(None, 1), PytestPluginManager())
     pytest_configure(config)
     pytest_unconfigure(config)
Example #15
0
    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")
Example #16
0
 def test_consider_env_fails_to_import(
     self, monkeypatch: MonkeyPatch, pytestpm: PytestPluginManager
 ) -> None:
     monkeypatch.setenv("PYTEST_PLUGINS", "nonexisting", prepend=",")
     with pytest.raises(ImportError):
         pytestpm.consider_env()