Example #1
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))
Example #2
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, importmode="prepend")
    assert len(values) == 1
Example #3
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 #4
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(), importmode="prepend")
    assert len(values) == 1
    assert values[0].__file__.startswith(str(conf))
Example #5
0
def test_doubledash_considered(pytester: Pytester) -> None:
    conf = pytester.mkdir("--option")
    conf.joinpath("conftest.py").touch()
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [conf.name, conf.name])
    values = conftest._getconftestmodules(conf, importmode="prepend")
    assert len(values) == 1
Example #6
0
def test_conftestcutdir_inplace_considered(pytester: Pytester) -> None:
    conf = pytester.makeconftest("")
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [conf.parent], confcutdir=conf.parent)
    values = conftest._getconftestmodules(conf.parent, importmode="prepend")
    assert len(values) == 1
    assert values[0].__file__.startswith(str(conf))
Example #7
0
def test_conftestcutdir_inplace_considered(testdir):
    conf = testdir.makeconftest("")
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [conf.dirpath()], confcutdir=conf.dirpath())
    l = conftest._getconftestmodules(conf.dirpath())
    assert len(l) == 1
    assert l[0].__file__.startswith(str(conf))
Example #8
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 #9
0
def test_doubledash_considered(testdir):
    conf = testdir.mkdir("--option")
    conf.join("conftest.py").ensure()
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [conf.basename, conf.basename])
    l = conftest._getconftestmodules(conf)
    assert len(l) == 1
Example #10
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 #11
0
def test_conftestcutdir(testdir: Testdir) -> None:
    conf = testdir.makeconftest("")
    p = testdir.mkdir("x")
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [testdir.tmpdir], confcutdir=p)
    values = conftest._getconftestmodules(p, importmode="prepend")
    assert len(values) == 0
    values = conftest._getconftestmodules(conf.dirpath(), importmode="prepend")
    assert len(values) == 0
    assert Path(conf) not in conftest._conftestpath2mod
    # but we can still import a conftest directly
    conftest._importconftest(conf, importmode="prepend")
    values = conftest._getconftestmodules(conf.dirpath(), importmode="prepend")
    assert values[0].__file__.startswith(str(conf))
    # and all sub paths get updated properly
    values = conftest._getconftestmodules(p, importmode="prepend")
    assert len(values) == 1
    assert values[0].__file__.startswith(str(conf))
Example #12
0
def test_conftestcutdir(testdir):
    conf = testdir.makeconftest("")
    p = testdir.mkdir("x")
    conftest = PytestPluginManager()
    conftest_setinitial(conftest, [testdir.tmpdir], confcutdir=p)
    l = conftest._getconftestmodules(p)
    assert len(l) == 0
    l = conftest._getconftestmodules(conf.dirpath())
    assert len(l) == 0
    assert conf not in conftest._conftestpath2mod
    # but we can still import a conftest directly
    conftest._importconftest(conf)
    l = conftest._getconftestmodules(conf.dirpath())
    assert l[0].__file__.startswith(str(conf))
    # and all sub paths get updated properly
    l = conftest._getconftestmodules(p)
    assert len(l) == 1
    assert l[0].__file__.startswith(str(conf))
Example #13
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 #14
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, importmode):
        return p

    conftest = PytestPluginManager()
    conftest._confcutdir = testdir.tmpdir
    monkeypatch.setattr(conftest, "_importconftest", impct)
    assert conftest._getconftestmodules(sub,
                                        importmode="prepend") == [ct1, ct2]
Example #15
0
def test_conftest_import_order(pytester: Pytester, monkeypatch: MonkeyPatch) -> None:
    ct1 = pytester.makeconftest("")
    sub = pytester.mkdir("sub")
    ct2 = sub / "conftest.py"
    ct2.write_text("")

    def impct(p, importmode):
        return p

    conftest = PytestPluginManager()
    conftest._confcutdir = pytester.path
    monkeypatch.setattr(conftest, "_importconftest", impct)
    mods = cast(List[Path], conftest._getconftestmodules(sub, importmode="prepend"))
    expected = [ct1, ct2]
    assert mods == expected
Example #16
0
 def test_immediate_initialiation_and_incremental_are_the_same(self, basedir):
     conftest = PytestPluginManager()
     assert not len(conftest._dirpath2confmods)
     conftest._getconftestmodules(basedir)
     snap1 = len(conftest._dirpath2confmods)
     assert snap1 == 1
     conftest._getconftestmodules(basedir.join("adir"))
     assert len(conftest._dirpath2confmods) == snap1 + 1
     conftest._getconftestmodules(basedir.join("b"))
     assert len(conftest._dirpath2confmods) == snap1 + 2
Example #17
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 #18
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 #19
0
 def test_immediate_initialiation_and_incremental_are_the_same(
         self, basedir: Path) -> None:
     conftest = PytestPluginManager()
     assert not len(conftest._dirpath2confmods)
     conftest._getconftestmodules(basedir, importmode="prepend")
     snap1 = len(conftest._dirpath2confmods)
     assert snap1 == 1
     conftest._getconftestmodules(basedir / "adir", importmode="prepend")
     assert len(conftest._dirpath2confmods) == snap1 + 1
     conftest._getconftestmodules(basedir / "b", importmode="prepend")
     assert len(conftest._dirpath2confmods) == snap1 + 2
Example #20
0
def test_conftest_import_order(testdir: Testdir,
                               monkeypatch: MonkeyPatch) -> None:
    ct1 = testdir.makeconftest("")
    sub = testdir.mkdir("sub")
    ct2 = sub.join("conftest.py")
    ct2.write("")

    def impct(p, importmode):
        return p

    conftest = PytestPluginManager()
    conftest._confcutdir = testdir.tmpdir
    monkeypatch.setattr(conftest, "_importconftest", impct)
    mods = cast(
        List[py.path.local],
        conftest._getconftestmodules(py.path.local(sub), importmode="prepend"),
    )
    expected = [ct1, ct2]
    assert mods == expected