@@ -46,12 +46,12 @@ def test_cache_writefail_permissions(self, testdir):
46
46
def test_cache_failure_warns (self , testdir ):
47
47
testdir .tmpdir .ensure_dir ('.cache' ).chmod (0 )
48
48
testdir .makepyfile ("""
49
- def test_pass ():
50
- pass
49
+ def test_error ():
50
+ raise Exception
51
51
52
52
""" )
53
53
result = testdir .runpytest ('-rw' )
54
- assert result .ret == 0
54
+ assert result .ret == 1
55
55
result .stdout .fnmatch_lines ([
56
56
"*could not create cache path*" ,
57
57
"*1 pytest-warnings*" ,
@@ -266,7 +266,7 @@ def test_hello():
266
266
""" )
267
267
config = testdir .parseconfigure ()
268
268
lastfailed = config .cache .get ("cache/lastfailed" , - 1 )
269
- assert not lastfailed
269
+ assert lastfailed == - 1
270
270
271
271
def test_non_serializable_parametrize (self , testdir ):
272
272
"""Test that failed parametrized tests with unmarshable parameters
@@ -305,7 +305,7 @@ def rlf(fail_import, fail_run):
305
305
return lastfailed
306
306
307
307
lastfailed = rlf (fail_import = 0 , fail_run = 0 )
308
- assert not lastfailed
308
+ assert lastfailed == - 1
309
309
310
310
lastfailed = rlf (fail_import = 1 , fail_run = 0 )
311
311
assert list (lastfailed ) == ['test_maybe.py' ]
@@ -347,7 +347,7 @@ def rlf(fail_import, fail_run, args=()):
347
347
return result , lastfailed
348
348
349
349
result , lastfailed = rlf (fail_import = 0 , fail_run = 0 )
350
- assert not lastfailed
350
+ assert lastfailed == - 1
351
351
result .stdout .fnmatch_lines ([
352
352
'*3 passed*' ,
353
353
])
@@ -370,3 +370,17 @@ def rlf(fail_import, fail_run, args=()):
370
370
result .stdout .fnmatch_lines ([
371
371
'*2 passed*' ,
372
372
])
373
+
374
+ def test_lastfailed_creates_cache_when_needed (self , testdir ):
375
+ # Issue #1342
376
+ testdir .makepyfile (test_empty = '' )
377
+ testdir .runpytest ('-q' , '--lf' )
378
+ assert not os .path .exists ('.cache' )
379
+
380
+ testdir .makepyfile (test_successful = 'def test_success():\n assert True' )
381
+ testdir .runpytest ('-q' , '--lf' )
382
+ assert not os .path .exists ('.cache' )
383
+
384
+ testdir .makepyfile (test_errored = 'def test_error():\n assert False' )
385
+ testdir .runpytest ('-q' , '--lf' )
386
+ assert os .path .exists ('.cache' )
0 commit comments