예제 #1
0
    def test_cleanup_locked(self, tmp_path):
        p = make_numbered_dir(root=tmp_path, prefix=self.PREFIX)

        create_cleanup_lock(p)

        assert not pathlib.ensure_deletable(
            p, consider_lock_dead_if_created_before=p.stat().st_mtime - 1)
        assert pathlib.ensure_deletable(
            p, consider_lock_dead_if_created_before=p.stat().st_mtime + 1)
예제 #2
0
    def test_make(self, tmp_path):
        for i in range(10):
            d = make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
            assert d.name.startswith(self.PREFIX)
            assert d.name.endswith(str(i))

        symlink = tmp_path.joinpath(self.PREFIX + "current")
        if symlink.exists():
            # unix
            assert symlink.is_symlink()
            assert symlink.resolve() == d.resolve()
예제 #3
0
 def runpytest_subprocess(self, *args, **kwargs) -> RunResult:
     """
     Allow to pass stdin into ``run``.
     """
     __tracebackhide__ = True
     p = make_numbered_dir(root=Path(str(self.tmpdir)), prefix="runpytest-")
     args = ("--basetemp=%s" % p, ) + args
     plugins = [x for x in self.plugins if isinstance(x, str)]
     if plugins:
         args = ("-p", plugins[0]) + args
     args = self._getpytestargs() + args
     return self.run(*args, **kwargs)
예제 #4
0
    def test_make(self, tmp_path):
        from _pytest.pathlib import make_numbered_dir

        for i in range(10):
            d = make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
            assert d.name.startswith(self.PREFIX)
            assert d.name.endswith(str(i))

        symlink = tmp_path.joinpath(self.PREFIX + "current")
        if symlink.exists():
            # unix
            assert symlink.is_symlink()
            assert symlink.resolve() == d.resolve()
예제 #5
0
    def test_cleanup_locked(self, tmp_path):

        from _pytest import pathlib

        p = pathlib.make_numbered_dir(root=tmp_path, prefix=self.PREFIX)

        pathlib.create_cleanup_lock(p)

        assert not pathlib.ensure_deletable(
            p, consider_lock_dead_if_created_before=p.stat().st_mtime - 1
        )
        assert pathlib.ensure_deletable(
            p, consider_lock_dead_if_created_before=p.stat().st_mtime + 1
        )
예제 #6
0
 def test_pyc_vs_pyo(self, testdir, monkeypatch):
     testdir.makepyfile("""
         import pytest
         def test_optimized():
             "hello"
             assert test_optimized.__doc__ is None""")
     p = make_numbered_dir(root=Path(testdir.tmpdir), prefix="runpytest-")
     tmp = "--basetemp=%s" % p
     monkeypatch.setenv("PYTHONOPTIMIZE", "2")
     monkeypatch.delenv("PYTHONDONTWRITEBYTECODE", raising=False)
     assert testdir.runpytest_subprocess(tmp).ret == 0
     tagged = "test_pyc_vs_pyo." + PYTEST_TAG
     assert tagged + ".pyo" in os.listdir("__pycache__")
     monkeypatch.undo()
     monkeypatch.delenv("PYTHONDONTWRITEBYTECODE", raising=False)
     assert testdir.runpytest_subprocess(tmp).ret == 1
     assert tagged + ".pyc" in os.listdir("__pycache__")
예제 #7
0
 def test_removal_accepts_lock(self, tmp_path):
     folder = make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
     create_cleanup_lock(folder)
     maybe_delete_a_numbered_dir(folder)
     assert folder.is_dir()
예제 #8
0
 def test_removal_accepts_lock(self, tmp_path):
     folder = pathlib.make_numbered_dir(root=tmp_path, prefix=self.PREFIX)
     pathlib.create_cleanup_lock(folder)
     pathlib.maybe_delete_a_numbered_dir(folder)
     assert folder.is_dir()