'Test workflow where user fixes errors gradually file by file using --lf.'

def test_cache_cumulative(self, testdir):

    test_bar = testdir.makepyfile(test_bar='\n                                                def    test_bar_1():\n                                                                pass\n                                                def    test_bar_2():\n                                                                assert    0\n                                ')
    test_foo = testdir.makepyfile(test_foo='\n                                                def    test_foo_3():\n                                                                pass\n                                                def    test_foo_4():\n                                                                assert    0\n                                ')
    testdir.runpytest()
    assert (self.get_cached_last_failed(testdir) == ['test_bar.py::test_bar_2', 'test_foo.py::test_foo_4'])
    testdir.makepyfile(test_bar='\n                                                def    test_bar_1():\n                                                                pass\n                                                def    test_bar_2():\n                                                                pass\n                                ')
    result = testdir.runpytest(test_bar)
    result.stdout.fnmatch_lines('*2    passed*')
    assert (self.get_cached_last_failed(testdir) == ['test_foo.py::test_foo_4'])
    result = testdir.runpytest('--last-failed')
    result.stdout.fnmatch_lines('*1    failed,    3    deselected*')
    assert (self.get_cached_last_failed(testdir) == ['test_foo.py::test_foo_4'])
    test_foo = testdir.makepyfile(test_foo='\n                                                def    test_foo_3():\n                                                                pass\n                                                def    test_foo_4():\n                                                                pass\n                                ')
    result = testdir.runpytest(test_foo, '--last-failed')
    result.stdout.fnmatch_lines('*1    passed,    1    deselected*')
    assert (self.get_cached_last_failed(testdir) == [])
    result = testdir.runpytest('--last-failed')
    result.stdout.fnmatch_lines('*4    passed*')
    assert (self.get_cached_last_failed(testdir) == [])
