Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last-failed: smarter collection #5172

Closed
blueyed opened this issue Apr 26, 2019 · 2 comments

Comments

Projects
None yet
2 participants
@blueyed
Copy link
Contributor

commented Apr 26, 2019

With --lf it should not run a full collection, but use the information from the cache.

@nicoddemus

This comment has been minimized.

Copy link
Member

commented Apr 28, 2019

diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py
index ef2039539..2b76f9fff 100755
--- a/src/_pytest/cacheprovider.py
+++ b/src/_pytest/cacheprovider.py
@@ -159,6 +159,19 @@ class LFPlugin(object):
         self._previously_failed_count = None
         self._no_failures_behavior = self.config.getoption("last_failed_no_failures")

+    @property
+    def last_failed_paths(self):
+        result = getattr(self, '_last_failed_paths', None)
+        if result is None:
+            result = {Path(self.config.rootdir) / nodeid.split('::')[0] for nodeid in self.lastfailed}
+            self._last_failed_paths = result
+        return result
+
+    def pytest_ignore_collect(self, path):
+        if not self.active or not self.config.getoption("lf"):
+            return
+        return Path(path) not in self.last_failed_paths
+
     def pytest_report_collectionfinish(self):
         if self.active and self.config.getoption("verbose") >= 0:
             if not self._previously_failed_count:

Looks much easier than I thought... will open a PR later. 😁

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Apr 28, 2019

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Apr 28, 2019

@blueyed

This comment has been minimized.

Copy link
Contributor Author

commented Apr 28, 2019

Awesome, thanks!

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Apr 28, 2019

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Apr 28, 2019

nicoddemus added a commit to nicoddemus/pytest that referenced this issue Apr 28, 2019

@nicoddemus nicoddemus closed this Apr 29, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.