Skip to content

Commit 92b436c

Browse files
authored
Merge pull request #6136 from blueyed/fix-rm_rf-tests
Fix rm_rf tests
2 parents 01769b1 + d809692 commit 92b436c

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

testing/test_cacheprovider.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import shutil
3+
import stat
34
import sys
45
import textwrap
56

@@ -45,26 +46,40 @@ def test_cache_writefail_cachfile_silent(self, testdir):
4546
)
4647
def test_cache_writefail_permissions(self, testdir):
4748
testdir.makeini("[pytest]")
49+
cache_dir = str(testdir.tmpdir.ensure_dir(".pytest_cache"))
50+
mode = os.stat(cache_dir)[stat.ST_MODE]
4851
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(0)
49-
config = testdir.parseconfigure()
50-
cache = config.cache
51-
cache.set("test/broken", [])
52+
try:
53+
config = testdir.parseconfigure()
54+
cache = config.cache
55+
cache.set("test/broken", [])
56+
finally:
57+
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(mode)
5258

5359
@pytest.mark.skipif(sys.platform.startswith("win"), reason="no chmod on windows")
54-
@pytest.mark.filterwarnings("default")
60+
@pytest.mark.filterwarnings(
61+
"ignore:could not create cache path:pytest.PytestWarning"
62+
)
5563
def test_cache_failure_warns(self, testdir):
64+
cache_dir = str(testdir.tmpdir.ensure_dir(".pytest_cache"))
65+
mode = os.stat(cache_dir)[stat.ST_MODE]
5666
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(0)
57-
testdir.makepyfile(
58-
"""
59-
def test_error():
60-
raise Exception
67+
try:
68+
testdir.makepyfile(
69+
"""
70+
def test_error():
71+
raise Exception
6172
62-
"""
63-
)
64-
result = testdir.runpytest("-rw")
65-
assert result.ret == 1
66-
# warnings from nodeids, lastfailed, and stepwise
67-
result.stdout.fnmatch_lines(["*could not create cache path*", "*3 warnings*"])
73+
"""
74+
)
75+
result = testdir.runpytest("-rw")
76+
assert result.ret == 1
77+
# warnings from nodeids, lastfailed, and stepwise
78+
result.stdout.fnmatch_lines(
79+
["*could not create cache path*", "*3 warnings*"]
80+
)
81+
finally:
82+
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(mode)
6883

6984
def test_config_cache(self, testdir):
7085
testdir.makeconftest(

tox.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ filterwarnings =
142142
error
143143
default:Using or importing the ABCs:DeprecationWarning:unittest2.*
144144
ignore:Module already imported so cannot be rewritten:pytest.PytestWarning
145-
# https://github.com/pytest-dev/pytest/issues/5974
146-
default:\(rm_rf\) error removing.*:pytest.PytestWarning
147145
# produced by python3.6/site.py itself (3.6.7 on Travis, could not trigger it with 3.6.8).
148146
ignore:.*U.*mode is deprecated:DeprecationWarning:(?!(pytest|_pytest))
149147
# produced by pytest-xdist

0 commit comments

Comments
 (0)