3 new commits in pytest-cache:

https://bitbucket.org/hpk42/pytest-cache/changeset/e5eef3cca436/
changeset:   e5eef3cca436
user:        jriches
date:        2012-11-21 14:43:58
summary:     Add --failedfirst option to run previously failed tests at the 
start of the run

Includes unit test
affected #:  2 files

diff -r 0694bcab3d0c2f066b8c656dce20e8bb519192b6 -r 
e5eef3cca4365ad59c36427cfe226355a0018900 pytest_cache.py
--- a/pytest_cache.py
+++ b/pytest_cache.py
@@ -7,12 +7,16 @@
     group = parser.getgroup("general")
     group.addoption('--lf', action='store_true', dest="lf",
         help="rerun tests that failed at the last run")
+    group.addoption('--failedfirst', action='store_true', dest="failedfirst",
+        help="run tests that failed at the last run at the start of this run")
     group.addoption('--cache', action='store_true', dest="showcache",
         help="show cache contents, don't perform collection or tests")
     group.addoption('--clearcache', action='store_true', dest="clearcache",
         help="remove all cache contents at start of test run.")
 
 def pytest_cmdline_main(config):
+    if config.option.failedfirst and not config.option.lf:
+        raise pytest.UsageError("--failedfirst must be used with --lf")
     if config.option.showcache:
         from _pytest.main import wrap_session
         return wrap_session(config, showcache)
@@ -123,7 +127,9 @@
             if not self.lastfailed:
                 mode = "run all (no recorded failures)"
             else:
-                mode = "rerun last %d failures" % len(self.lastfailed)
+                mode = "rerun last %d failures%s" % (
+                    len(self.lastfailed),
+                    " first" if self.config.getvalue("failedfirst") else "")
             return "run-last-failure: %s" % mode
 
     def pytest_runtest_logreport(self, report):
@@ -137,15 +143,18 @@
 
     def pytest_collection_modifyitems(self, session, config, items):
         if self.config.getvalue("lf") and self.lastfailed:
-            newitems = []
-            deselected = []
+            previously_failed = []
+            previously_passed = []
             for item in items:
                 if item.nodeid in self.lastfailed:
-                    newitems.append(item)
+                    previously_failed.append(item)
                 else:
-                    deselected.append(item)
-            items[:] = newitems
-            config.hook.pytest_deselected(items=deselected)
+                    previously_passed.append(item)
+            if self.config.getvalue("failedfirst"):
+                items[:] = previously_failed + previously_passed
+            else:
+                items[:] = previously_failed
+                config.hook.pytest_deselected(items=previously_failed)
 
     def pytest_sessionfinish(self, session):
         config = self.config


diff -r 0694bcab3d0c2f066b8c656dce20e8bb519192b6 -r 
e5eef3cca4365ad59c36427cfe226355a0018900 test_cache.py
--- a/test_cache.py
+++ b/test_cache.py
@@ -161,6 +161,28 @@
             "*2 failed*",
         ])
 
+    def test_lastfailed_order(self, testdir):
+        always_pass = testdir.tmpdir.join('test_a.py').write(py.code.Source("""
+            def test_always_passes():
+                assert 1
+        """))
+        always_fail = testdir.tmpdir.join('test_b.py').write(py.code.Source("""
+            def test_always_fails():
+                assert 0
+        """))
+        result = testdir.runpytest()
+        # Test order will be collection order; alphabetical
+        result.stdout.fnmatch_lines([
+            "test_a.py*",
+            "test_b.py*",
+        ])
+        result = testdir.runpytest("--lf", "--failedfirst")
+        # Test order will be failing tests firs
+        result.stdout.fnmatch_lines([
+            "test_b.py*",
+            "test_a.py*",
+        ])
+
     @pytest.mark.skipif("sys.version_info < (2,6)")
     def test_lastfailed_failure_to_skip_is_passsed(self, testdir, monkeypatch):
         monkeypatch.setenv("PYTHONDONTWRITEBYTECODE", 1)



https://bitbucket.org/hpk42/pytest-cache/changeset/1f81c9f64ece/
changeset:   1f81c9f64ece
user:        jriches
date:        2012-11-21 15:58:40
summary:     Provide short argument -ff for Failed First. Fix bug with wrong 
tests being deselected
affected #:  2 files

diff -r e5eef3cca4365ad59c36427cfe226355a0018900 -r 
1f81c9f64ece05b1c630a5b7348a94261270658f pytest_cache.py
--- a/pytest_cache.py
+++ b/pytest_cache.py
@@ -7,16 +7,15 @@
     group = parser.getgroup("general")
     group.addoption('--lf', action='store_true', dest="lf",
         help="rerun tests that failed at the last run")
-    group.addoption('--failedfirst', action='store_true', dest="failedfirst",
-        help="run tests that failed at the last run at the start of this run")
+    group.addoption('--ff', action='store_true', dest="failedfirst",
+        help="run tests that failed at the last run at the start of this run. "
+             "re-orders tests - may lead to repeated fixture setup/teardown")
     group.addoption('--cache', action='store_true', dest="showcache",
         help="show cache contents, don't perform collection or tests")
     group.addoption('--clearcache', action='store_true', dest="clearcache",
         help="remove all cache contents at start of test run.")
 
 def pytest_cmdline_main(config):
-    if config.option.failedfirst and not config.option.lf:
-        raise pytest.UsageError("--failedfirst must be used with --lf")
     if config.option.showcache:
         from _pytest.main import wrap_session
         return wrap_session(config, showcache)
@@ -117,13 +116,14 @@
     """ Plugin which implements the --lf (run last-failing) option """
     def __init__(self, config):
         self.config = config
-        if config.getvalue("lf"):
+        self.active = config.getvalue("lf") or config.getvalue("failedfirst")
+        if self.active:
             self.lastfailed = config.cache.get("cache/lastfailed", set())
         else:
             self.lastfailed = set()
 
     def pytest_report_header(self):
-        if self.config.getvalue("lf"):
+        if self.active:
             if not self.lastfailed:
                 mode = "run all (no recorded failures)"
             else:
@@ -142,7 +142,7 @@
                 self.lastfailed.discard(report.nodeid)
 
     def pytest_collection_modifyitems(self, session, config, items):
-        if self.config.getvalue("lf") and self.lastfailed:
+        if self.active and self.lastfailed:
             previously_failed = []
             previously_passed = []
             for item in items:
@@ -154,7 +154,7 @@
                 items[:] = previously_failed + previously_passed
             else:
                 items[:] = previously_failed
-                config.hook.pytest_deselected(items=previously_failed)
+                config.hook.pytest_deselected(items=previously_passed)
 
     def pytest_sessionfinish(self, session):
         config = self.config


diff -r e5eef3cca4365ad59c36427cfe226355a0018900 -r 
1f81c9f64ece05b1c630a5b7348a94261270658f test_cache.py
--- a/test_cache.py
+++ b/test_cache.py
@@ -176,7 +176,7 @@
             "test_a.py*",
             "test_b.py*",
         ])
-        result = testdir.runpytest("--lf", "--failedfirst")
+        result = testdir.runpytest("--lf", "--ff")
         # Test order will be failing tests firs
         result.stdout.fnmatch_lines([
             "test_b.py*",



https://bitbucket.org/hpk42/pytest-cache/changeset/83120fec0698/
changeset:   83120fec0698
user:        jriches
date:        2012-11-21 20:41:07
summary:     Rename test to test_failedfirst_order
affected #:  1 file

diff -r 1f81c9f64ece05b1c630a5b7348a94261270658f -r 
83120fec0698330dd3169661e9ec2fe545666a55 test_cache.py
--- a/test_cache.py
+++ b/test_cache.py
@@ -161,7 +161,7 @@
             "*2 failed*",
         ])
 
-    def test_lastfailed_order(self, testdir):
+    def test_failedfirst_order(self, testdir):
         always_pass = testdir.tmpdir.join('test_a.py').write(py.code.Source("""
             def test_always_passes():
                 assert 1

Repository URL: https://bitbucket.org/hpk42/pytest-cache/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.
_______________________________________________
py-svn mailing list
py-svn@codespeak.net
http://codespeak.net/mailman/listinfo/py-svn

Reply via email to