Skip to content

Commit 2b5adc8

Browse files
committed
Move test_issue4445_cacheprovider_set into test_cache_failure_warns
Would need to be adjusted anyway non-trivially, and we can just harden `test_cache_failure_warns` instead.
1 parent 02aa8ad commit 2b5adc8

File tree

2 files changed

+9
-22
lines changed

2 files changed

+9
-22
lines changed

testing/test_cacheprovider.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,15 @@ def test_cache_failure_warns(self, testdir, monkeypatch):
6868
assert result.ret == 1
6969
# warnings from nodeids, lastfailed, and stepwise
7070
result.stdout.fnmatch_lines(
71-
["*could not create cache path*", "*3 warnings*"]
71+
[
72+
# Validate location/stacklevel of warning from cacheprovider.
73+
"*= warnings summary =*",
74+
"*/cacheprovider.py:314",
75+
" */cacheprovider.py:314: PytestCacheWarning: could not create cache path "
76+
"{}/v/cache/nodeids".format(cache_dir),
77+
' config.cache.set("cache/nodeids", self.cached_nodeids)',
78+
"*1 failed, 3 warnings in*",
79+
]
7280
)
7381
finally:
7482
testdir.tmpdir.ensure_dir(".pytest_cache").chmod(mode)

testing/test_warnings.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -712,27 +712,6 @@ def test_dummy():
712712
assert "resultlog.py" in file
713713
assert func == "pytest_configure"
714714

715-
def test_issue4445_cacheprovider_set(self, testdir, capwarn):
716-
"""#4445: Make sure the warning points to a reasonable location
717-
See origin of _issue_warning_captured at: _pytest.cacheprovider.py:59
718-
"""
719-
testdir.tmpdir.join(".pytest_cache").write("something wrong")
720-
testdir.runpytest(plugins=[capwarn()])
721-
722-
# with stacklevel=3 the warning originates from one stacklevel above
723-
# _issue_warning_captured in cacheprovider.Cache.set and is thrown
724-
# when there are errors during cache folder creation
725-
726-
# set is called twice (in module stepwise and in cacheprovider) so emits
727-
# two warnings when there are errors during cache folder creation. (is this intentional?)
728-
assert len(capwarn.captured) == 2
729-
warning, location = capwarn.captured.pop()
730-
file, lineno, func = location
731-
732-
assert "could not create cache path" in str(warning.message)
733-
assert "cacheprovider.py" in file
734-
assert func == "set"
735-
736715
def test_issue4445_issue5928_mark_generator(self, testdir):
737716
"""#4445 and #5928: Make sure the warning from an unknown mark points to
738717
the test file where this mark is used.

0 commit comments

Comments
 (0)