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)
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()
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)
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()
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 )
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__")
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()
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()