|
1 | 1 | import os |
2 | 2 | import shutil |
| 3 | +import stat |
3 | 4 | import sys |
4 | 5 | import textwrap |
5 | 6 |
|
@@ -45,26 +46,40 @@ def test_cache_writefail_cachfile_silent(self, testdir): |
45 | 46 | ) |
46 | 47 | def test_cache_writefail_permissions(self, testdir): |
47 | 48 | testdir.makeini("[pytest]") |
| 49 | + cache_dir = str(testdir.tmpdir.ensure_dir(".pytest_cache")) |
| 50 | + mode = os.stat(cache_dir)[stat.ST_MODE] |
48 | 51 | 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) |
52 | 58 |
|
53 | 59 | @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 | + ) |
55 | 63 | 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] |
56 | 66 | 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 |
61 | 72 |
|
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) |
68 | 83 |
|
69 | 84 | def test_config_cache(self, testdir): |
70 | 85 | testdir.makeconftest( |
|
0 commit comments