From 1d137fd2fecfcaf3527f331eca56f9c77df12cd5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 7 Apr 2019 15:03:22 +0200 Subject: [PATCH 1/5] minor: LFPlugin: de-indent code by returning if not active --- src/_pytest/cacheprovider.py | 70 ++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py index a1200ce37..63503ed2e 100755 --- a/src/_pytest/cacheprovider.py +++ b/src/_pytest/cacheprovider.py @@ -179,45 +179,45 @@ class LFPlugin(object): self.lastfailed[report.nodeid] = True def pytest_collection_modifyitems(self, session, config, items): - if self.active: - if self.lastfailed: - previously_failed = [] - previously_passed = [] - for item in items: - if item.nodeid in self.lastfailed: - previously_failed.append(item) - else: - previously_passed.append(item) - self._previously_failed_count = len(previously_failed) + if not self.active: + return - if not previously_failed: - # Running a subset of all tests with recorded failures - # only outside of it. - self._report_status = "%d known failures not in selected tests" % ( - len(self.lastfailed), - ) + if self.lastfailed: + previously_failed = [] + previously_passed = [] + for item in items: + if item.nodeid in self.lastfailed: + previously_failed.append(item) else: - if self.config.getoption("lf"): - items[:] = previously_failed - config.hook.pytest_deselected(items=previously_passed) - else: # --failedfirst - items[:] = previously_failed + previously_passed + previously_passed.append(item) + self._previously_failed_count = len(previously_failed) - noun = ( - "failure" if self._previously_failed_count == 1 else "failures" - ) - 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 - ) + if not previously_failed: + # Running a subset of all tests with recorded failures + # only outside of it. + self._report_status = "%d known failures not in selected tests" % ( + len(self.lastfailed), + ) else: - self._report_status = "no previously failed tests, " - if self.config.getoption("last_failed_no_failures") == "none": - self._report_status += "deselecting all items." - config.hook.pytest_deselected(items=items) - items[:] = [] - else: - self._report_status += "not deselecting items." + if self.config.getoption("lf"): + items[:] = previously_failed + config.hook.pytest_deselected(items=previously_passed) + else: # --failedfirst + items[:] = previously_failed + previously_passed + + noun = "failure" if self._previously_failed_count == 1 else "failures" + 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 + ) + else: + self._report_status = "no previously failed tests, " + if self.config.getoption("last_failed_no_failures") == "none": + self._report_status += "deselecting all items." + config.hook.pytest_deselected(items=items) + items[:] = [] + else: + self._report_status += "not deselecting items." def pytest_sessionfinish(self, session): config = self.config From bd1a2e6435d770e9e5d007f1329941ab3cd1db92 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 8 Apr 2019 12:42:30 +0200 Subject: [PATCH 2/5] fix typo --- src/_pytest/mark/structures.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/mark/structures.py b/src/_pytest/mark/structures.py index f3602b2d5..cda16c7ad 100644 --- a/src/_pytest/mark/structures.py +++ b/src/_pytest/mark/structures.py @@ -298,7 +298,7 @@ class MarkGenerator(object): for line in self._config.getini("markers"): # example lines: "skipif(condition): skip the given test if..." # or "hypothesis: tests which use Hypothesis", so to get the - # marker name we we split on both `:` and `(`. + # marker name we split on both `:` and `(`. marker = line.split(":")[0].split("(")[0].strip() self._markers.add(marker) From 992e7f7771646ecd80c10c11ae50666bccc6437e Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 13 Apr 2019 18:51:27 +0200 Subject: [PATCH 3/5] rename variable --- src/_pytest/terminal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_pytest/terminal.py b/src/_pytest/terminal.py index 2d7132259..46b624888 100644 --- a/src/_pytest/terminal.py +++ b/src/_pytest/terminal.py @@ -453,10 +453,10 @@ class TerminalReporter(object): progress_length = len(" [100%]") self._progress_nodeids_reported.add(nodeid) - last_item = ( + is_last_item = ( len(self._progress_nodeids_reported) == self._session.testscollected ) - if last_item: + if is_last_item: self._write_progress_information_filling_space() else: w = self._width_of_current_line From e804e419bc5bd3ee2115b49c958488c53ffe9863 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 14 Apr 2019 23:49:24 +0200 Subject: [PATCH 4/5] remove unnecessary newline --- src/_pytest/config/__init__.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 4542f06ab..d77561f85 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -282,7 +282,6 @@ class PytestPluginManager(PluginManager): known_marks = {m.name for m in getattr(method, "pytestmark", [])} for name in ("tryfirst", "trylast", "optionalhook", "hookwrapper"): - opts.setdefault(name, hasattr(method, name) or name in known_marks) return opts From c43a9c83eec4b9f996c53a465ffb4f2b69c19e7e Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 14 Apr 2019 23:50:14 +0200 Subject: [PATCH 5/5] doc: pytest_deselected: not only via keywords --- src/_pytest/hookspec.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 5a3eb282d..25c2c3cbc 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -227,7 +227,7 @@ def pytest_collectreport(report): def pytest_deselected(items): - """ called for test items deselected by keyword. """ + """ called for test items deselected, e.g. by keyword. """ @hookspec(firstresult=True)