@@ -158,6 +158,33 @@ class LFPlugin(object):
|
||||
self.lastfailed = config.cache.get("cache/lastfailed", {})
|
||||
self._previously_failed_count = None
|
||||
self._report_status = None
|
||||
self._skipped_files = 0 # count skipped files during collection due to --lf
|
||||
|
||||
def last_failed_paths(self):
|
||||
"""Returns a set with all Paths()s of the previously failed nodeids (cached).
|
||||
"""
|
||||
result = getattr(self, "_last_failed_paths", None)
|
||||
if result is None:
|
||||
rootpath = Path(self.config.rootdir)
|
||||
result = {rootpath / nodeid.split("::")[0] for nodeid in self.lastfailed}
|
||||
self._last_failed_paths = result
|
||||
return result
|
||||
|
||||
def pytest_ignore_collect(self, path):
|
||||
"""
|
||||
Ignore this file path if we are in --lf mode and it is not in the list of
|
||||
previously failed files.
|
||||
"""
|
||||
if (
|
||||
self.active
|
||||
and self.config.getoption("lf")
|
||||
and path.isfile()
|
||||
and self.lastfailed
|
||||
):
|
||||
skip_it = Path(path) not in self.last_failed_paths()
|
||||
if skip_it:
|
||||
self._skipped_files += 1
|
||||
return skip_it
|
||||
|
||||
def pytest_report_collectionfinish(self):
|
||||
if self.active and self.config.getoption("verbose") >= 0:
|
||||
@@ -206,9 +233,19 @@ class LFPlugin(object):
|
||||
items[:] = previously_failed + previously_passed
|
||||
|
||||
noun = "failure" if self._previously_failed_count == 1 else "failures"
|
||||
if self._skipped_files > 0:
|
||||
files_noun = "file" if self._skipped_files == 1 else "files"
|
||||
skipped_files_msg = " (skipped {files} {files_noun})".format(
|
||||
files=self._skipped_files, files_noun=files_noun
|
||||
)
|
||||
else:
|
||||
skipped_files_msg = ""
|
||||
suffix = " first" if self.config.getoption("failedfirst") else ""
|
||||
self._report_status = "rerun previous {count} {noun}{suffix}".format(
|
||||
count=self._previously_failed_count, suffix=suffix, noun=noun
|
||||
self._report_status = "rerun previous {count} {noun}{suffix}{skipped_files}".format(
|
||||
count=self._previously_failed_count,
|
||||
suffix=suffix,
|
||||
noun=noun,
|
||||
skipped_files=skipped_files_msg,
|
||||
)
|
||||
else:
|
||||
self._report_status = "no previously failed tests, "
|
||||
|
||||
Reference in New Issue
Block a user