From 262ed567d065cf2455f988a60def75133a711345 Mon Sep 17 00:00:00 2001 From: Tibor Arpas Date: Tue, 5 Nov 2019 22:10:27 +0100 Subject: [PATCH 1/4] tests: clean up chmod-related tests to fix rm_rf warnings Fixed https://github.com/pytest-dev/pytest/issues/5974#issuecomment-549822509. --- testing/test_cacheprovider.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index dfc3c5320..6513909bc 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -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*"]) From dc2c51302ab06f9f643944fee788839de8d26b33 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 5 Nov 2019 22:11:56 +0100 Subject: [PATCH 2/4] Revert "tests: filterwarnings: do not crash with "(rm_rf)" warning" This reverts commit 6b2bae9392f4fdbf295fbca8082e58f280c90aac. --- tox.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/tox.ini b/tox.ini index edc9a5667..93889322f 100644 --- a/tox.ini +++ b/tox.ini @@ -142,8 +142,6 @@ filterwarnings = error default:Using or importing the ABCs:DeprecationWarning:unittest2.* ignore:Module already imported so cannot be rewritten:pytest.PytestWarning - # https://github.com/pytest-dev/pytest/issues/5974 - default:\(rm_rf\) error removing.*:pytest.PytestWarning # produced by python3.6/site.py itself (3.6.7 on Travis, could not trigger it with 3.6.8). ignore:.*U.*mode is deprecated:DeprecationWarning:(?!(pytest|_pytest)) # produced by pytest-xdist From 9309ae299ae94caf66187f98ad500ef6f082d762 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 5 Nov 2019 22:28:32 +0100 Subject: [PATCH 3/4] Use try/finally to ensure chmod is run, filter warning --- testing/test_cacheprovider.py | 40 +++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index 6513909bc..6a5a5af8b 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -48,28 +48,36 @@ class TestNewAPI: 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) + try: + config = testdir.parseconfigure() + cache = config.cache + cache.set("test/broken", []) + finally: + testdir.tmpdir.ensure_dir(".pytest_cache").chmod(mode) @pytest.mark.skipif(sys.platform.startswith("win"), reason="no chmod on windows") - @pytest.mark.filterwarnings("default") + @pytest.mark.filterwarnings( + "ignore:could not create cache path:pytest.PytestWarning" + ) 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( - """ - def test_error(): - raise Exception + try: + testdir.makepyfile( + """ + def test_error(): + raise Exception - """ - ) - 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*"]) + """ + ) + result = testdir.runpytest("-rw") + assert result.ret == 1 + # warnings from nodeids, lastfailed, and stepwise + result.stdout.fnmatch_lines( + ["*could not create cache path*", "*3 warnings*"] + ) + finally: + testdir.tmpdir.ensure_dir(".pytest_cache").chmod(mode) def test_config_cache(self, testdir): testdir.makeconftest( From d8096925fac4093deda89bc952e12e46bb9557ab Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 5 Nov 2019 23:04:27 +0100 Subject: [PATCH 4/4] Fix for Python 3.5 not handling LocalPath --- testing/test_cacheprovider.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index 6a5a5af8b..3f03b5ff9 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -46,7 +46,8 @@ class TestNewAPI: ) def test_cache_writefail_permissions(self, testdir): testdir.makeini("[pytest]") - mode = os.stat(testdir.tmpdir.ensure_dir(".pytest_cache"))[stat.ST_MODE] + cache_dir = str(testdir.tmpdir.ensure_dir(".pytest_cache")) + mode = os.stat(cache_dir)[stat.ST_MODE] testdir.tmpdir.ensure_dir(".pytest_cache").chmod(0) try: config = testdir.parseconfigure() @@ -60,7 +61,8 @@ class TestNewAPI: "ignore:could not create cache path:pytest.PytestWarning" ) def test_cache_failure_warns(self, testdir): - mode = os.stat(testdir.tmpdir.ensure_dir(".pytest_cache"))[stat.ST_MODE] + cache_dir = str(testdir.tmpdir.ensure_dir(".pytest_cache")) + mode = os.stat(cache_dir)[stat.ST_MODE] testdir.tmpdir.ensure_dir(".pytest_cache").chmod(0) try: testdir.makepyfile(