From 89bd7540a898610c5745ee4db2e572e669d9f865 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 4 Mar 2019 16:17:43 +0100 Subject: [PATCH 1/4] [WIP] add assertions to _ensure_supporting_files Coverage changes by Codecov indicate that this might not be the case: https://codecov.io/gh/pytest-dev/pytest/compare/f3f6cb20933c2e1e0377d5297eb35877e8781102...83558a0ba3a737752deb7d0b1c78a0ef0ec0843c/changes This is mainly for debugging this first, since it appears to be flaky (e.g. due to xdist). --- src/_pytest/cacheprovider.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index 0c25914bbf1..e8e30c402c4 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -139,13 +139,18 @@ def set(self, key, value): def _ensure_supporting_files(self): """Create supporting files in the cache dir that are not really part of the cache.""" readme_path = self._cachedir / "README.md" + assert not readme_path.exists(), "{} exists already".format(readme_path) readme_path.write_text(README_CONTENT) gitignore_path = self._cachedir.joinpath(".gitignore") msg = u"# Created by pytest automatically.\n*" + assert not gitignore_path.exists(), "{} exists already".format(gitignore_path) gitignore_path.write_text(msg, encoding="UTF-8") cachedir_tag_path = self._cachedir.joinpath("CACHEDIR.TAG") + assert not cachedir_tag_path.exists(), "{} exists already".format( + cachedir_tag_path + ) cachedir_tag_path.write_bytes(CACHEDIR_TAG_CONTENT) From a6b56ca79943faf341fe67d9e757e2a37207ddb5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 4 Mar 2019 16:21:34 +0100 Subject: [PATCH 2/4] handle race --- src/_pytest/cacheprovider.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index e8e30c402c4..c27ff091eed 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -138,6 +138,9 @@ def set(self, key, value): def _ensure_supporting_files(self): """Create supporting files in the cache dir that are not really part of the cache.""" + if self._cachedir.exists(): + return + readme_path = self._cachedir / "README.md" assert not readme_path.exists(), "{} exists already".format(readme_path) readme_path.write_text(README_CONTENT) From e8234bc9002f863f3694ea902b6b350bc5697950 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 4 Mar 2019 16:42:37 +0100 Subject: [PATCH 3/4] Revert "handle race" This reverts commit bb662a964e6665b139a001e16f87bd29537e27ec. --- src/_pytest/cacheprovider.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index c27ff091eed..e8e30c402c4 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -138,9 +138,6 @@ def set(self, key, value): def _ensure_supporting_files(self): """Create supporting files in the cache dir that are not really part of the cache.""" - if self._cachedir.exists(): - return - readme_path = self._cachedir / "README.md" assert not readme_path.exists(), "{} exists already".format(readme_path) readme_path.write_text(README_CONTENT) From 8b976011fc807a783761a73297b1cdd484ef5bf8 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 4 Mar 2019 16:42:51 +0100 Subject: [PATCH 4/4] minor: rename inner test --- testing/test_cacheprovider.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testing/test_cacheprovider.py b/testing/test_cacheprovider.py index 35a7232ab0e..082b097ee91 100644 --- a/testing/test_cacheprovider.py +++ b/testing/test_cacheprovider.py @@ -884,7 +884,7 @@ def test_always_passes(): def test_readme_failed(self, testdir): testdir.makepyfile( """ - def test_always_passes(): + def test_always_fails(): assert 0 """ )