Commits

Ronny Pfannschmidt  committed ab97c6f

handle collect failures

  • Participants
  • Parent commits 02ab82f

Comments (0)

Files changed (3)

 1.0
 ----------------------------------------------
 
+- handle collect failures by considering all tests
+  below a failed collector as failed
+
 - merged "--ff" (failedfirst) option to run all tests but 
   run the last-failed ones first. Thanks Jack Riches.
 

File pytest_cache.py

                 except KeyError:
                     pass
 
+    def pytest_collectreport(self, report):
+        passed = report.outcome in ('passed', 'skipped')
+
+        if passed:
+            if report.nodeid in self.lastfailed:
+                self.lastfailed.discard(report.nodeid)
+                self.lastfailed.update(item.nodeid for item in report.result)
+        else:
+            self.lastfailed.add(report.nodeid)
+
     def pytest_collection_modifyitems(self, session, config, items):
         if self.active and self.lastfailed:
             previously_failed = []

File test_cache.py

         config = testdir.parseconfigure()
         lastfailed = config.cache.get("cache/lastfailed", -1)
         assert not lastfailed
+
+    def test_lastfailed_collectfailure(self, testdir, monkeypatch):
+
+        testdir.makepyfile(test_maybe="""
+            import py
+            env = py.std.os.environ
+            if '1' == env['FAILIMPORT']:
+                raise ImportError('fail')
+            def test_hello():
+                assert '0' == env['FAILTEST']
+        """)
+
+        def rlf(fail_import, fail_run):
+            monkeypatch.setenv('FAILIMPORT', fail_import)
+            monkeypatch.setenv('FAILTEST', fail_run)
+
+            testdir.runpytest('-q')
+            config = testdir.parseconfigure()
+            lastfailed = config.cache.get("cache/lastfailed", -1)
+            return lastfailed
+
+        lastfailed = rlf(fail_import=0, fail_run=0)
+        assert not lastfailed
+
+        lastfailed = rlf(fail_import=1, fail_run=0)
+        assert lastfailed == set(['test_maybe.py'])
+
+        lastfailed = rlf(fail_import=0, fail_run=1)
+        assert lastfailed == set(['test_maybe.py::test_hello'])