tests: clean up chmod-related tests to fix rm_rf warnings

Fixed https://github.com/pytest-dev/pytest/issues/5974#issuecomment-549822509.
This commit is contained in:
Tibor Arpas 2019-11-05 22:10:27 +01:00 committed by Daniel Hahler
parent 0794289689
commit 262ed567d0
1 changed files with 5 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import os
import shutil
import stat
import sys
import textwrap
@ -45,14 +46,17 @@ class TestNewAPI:
)
def test_cache_writefail_permissions(self, testdir):
testdir.makeini("[pytest]")
mode = os.stat(testdir.tmpdir.ensure_dir(".pytest_cache"))[stat.ST_MODE]
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(0)
config = testdir.parseconfigure()
cache = config.cache
cache.set("test/broken", [])
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(mode)
@pytest.mark.skipif(sys.platform.startswith("win"), reason="no chmod on windows")
@pytest.mark.filterwarnings("default")
def test_cache_failure_warns(self, testdir):
mode = os.stat(testdir.tmpdir.ensure_dir(".pytest_cache"))[stat.ST_MODE]
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(0)
testdir.makepyfile(
"""
@ -62,6 +66,7 @@ class TestNewAPI:
"""
)
result = testdir.runpytest("-rw")
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(mode)
assert result.ret == 1
# warnings from nodeids, lastfailed, and stepwise
result.stdout.fnmatch_lines(["*could not create cache path*", "*3 warnings*"])