Merge pull request #1391 from malinoff/issue1342
LastFailed now creates .cache only when needed. Fixes #1342
This commit is contained in:
commit
4636bf6160
|
@ -149,6 +149,8 @@ class LFPlugin:
|
||||||
config = self.config
|
config = self.config
|
||||||
if config.getvalue("cacheshow") or hasattr(config, "slaveinput"):
|
if config.getvalue("cacheshow") or hasattr(config, "slaveinput"):
|
||||||
return
|
return
|
||||||
|
prev_failed = config.cache.get("cache/lastfailed", None) is not None
|
||||||
|
if (session.testscollected and prev_failed) or self.lastfailed:
|
||||||
config.cache.set("cache/lastfailed", self.lastfailed)
|
config.cache.set("cache/lastfailed", self.lastfailed)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -46,12 +46,12 @@ class TestNewAPI:
|
||||||
def test_cache_failure_warns(self, testdir):
|
def test_cache_failure_warns(self, testdir):
|
||||||
testdir.tmpdir.ensure_dir('.cache').chmod(0)
|
testdir.tmpdir.ensure_dir('.cache').chmod(0)
|
||||||
testdir.makepyfile("""
|
testdir.makepyfile("""
|
||||||
def test_pass():
|
def test_error():
|
||||||
pass
|
raise Exception
|
||||||
|
|
||||||
""")
|
""")
|
||||||
result = testdir.runpytest('-rw')
|
result = testdir.runpytest('-rw')
|
||||||
assert result.ret == 0
|
assert result.ret == 1
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
"*could not create cache path*",
|
"*could not create cache path*",
|
||||||
"*1 pytest-warnings*",
|
"*1 pytest-warnings*",
|
||||||
|
@ -266,7 +266,7 @@ class TestLastFailed:
|
||||||
""")
|
""")
|
||||||
config = testdir.parseconfigure()
|
config = testdir.parseconfigure()
|
||||||
lastfailed = config.cache.get("cache/lastfailed", -1)
|
lastfailed = config.cache.get("cache/lastfailed", -1)
|
||||||
assert not lastfailed
|
assert lastfailed == -1
|
||||||
|
|
||||||
def test_non_serializable_parametrize(self, testdir):
|
def test_non_serializable_parametrize(self, testdir):
|
||||||
"""Test that failed parametrized tests with unmarshable parameters
|
"""Test that failed parametrized tests with unmarshable parameters
|
||||||
|
@ -305,7 +305,7 @@ class TestLastFailed:
|
||||||
return lastfailed
|
return lastfailed
|
||||||
|
|
||||||
lastfailed = rlf(fail_import=0, fail_run=0)
|
lastfailed = rlf(fail_import=0, fail_run=0)
|
||||||
assert not lastfailed
|
assert lastfailed == -1
|
||||||
|
|
||||||
lastfailed = rlf(fail_import=1, fail_run=0)
|
lastfailed = rlf(fail_import=1, fail_run=0)
|
||||||
assert list(lastfailed) == ['test_maybe.py']
|
assert list(lastfailed) == ['test_maybe.py']
|
||||||
|
@ -347,7 +347,7 @@ class TestLastFailed:
|
||||||
return result, lastfailed
|
return result, lastfailed
|
||||||
|
|
||||||
result, lastfailed = rlf(fail_import=0, fail_run=0)
|
result, lastfailed = rlf(fail_import=0, fail_run=0)
|
||||||
assert not lastfailed
|
assert lastfailed == -1
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
'*3 passed*',
|
'*3 passed*',
|
||||||
])
|
])
|
||||||
|
@ -370,3 +370,17 @@ class TestLastFailed:
|
||||||
result.stdout.fnmatch_lines([
|
result.stdout.fnmatch_lines([
|
||||||
'*2 passed*',
|
'*2 passed*',
|
||||||
])
|
])
|
||||||
|
|
||||||
|
def test_lastfailed_creates_cache_when_needed(self, testdir):
|
||||||
|
# Issue #1342
|
||||||
|
testdir.makepyfile(test_empty='')
|
||||||
|
testdir.runpytest('-q', '--lf')
|
||||||
|
assert not os.path.exists('.cache')
|
||||||
|
|
||||||
|
testdir.makepyfile(test_successful='def test_success():\n assert True')
|
||||||
|
testdir.runpytest('-q', '--lf')
|
||||||
|
assert not os.path.exists('.cache')
|
||||||
|
|
||||||
|
testdir.makepyfile(test_errored='def test_error():\n assert False')
|
||||||
|
testdir.runpytest('-q', '--lf')
|
||||||
|
assert os.path.exists('.cache')
|
||||||
|
|
Loading…
Reference in New Issue