Skip to content

Commit 5530d3e

Browse files
authored
Merge pull request #5120 from blueyed/minor
A collection of minor code tweaks
2 parents c8b904a + c43a9c8 commit 5530d3e

File tree

5 files changed

+41
-42
lines changed

5 files changed

+41
-42
lines changed

src/_pytest/cacheprovider.py

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -179,45 +179,45 @@ def pytest_collectreport(self, report):
179179
self.lastfailed[report.nodeid] = True
180180

181181
def pytest_collection_modifyitems(self, session, config, items):
182-
if self.active:
183-
if self.lastfailed:
184-
previously_failed = []
185-
previously_passed = []
186-
for item in items:
187-
if item.nodeid in self.lastfailed:
188-
previously_failed.append(item)
189-
else:
190-
previously_passed.append(item)
191-
self._previously_failed_count = len(previously_failed)
192-
193-
if not previously_failed:
194-
# Running a subset of all tests with recorded failures
195-
# only outside of it.
196-
self._report_status = "%d known failures not in selected tests" % (
197-
len(self.lastfailed),
198-
)
182+
if not self.active:
183+
return
184+
185+
if self.lastfailed:
186+
previously_failed = []
187+
previously_passed = []
188+
for item in items:
189+
if item.nodeid in self.lastfailed:
190+
previously_failed.append(item)
199191
else:
200-
if self.config.getoption("lf"):
201-
items[:] = previously_failed
202-
config.hook.pytest_deselected(items=previously_passed)
203-
else: # --failedfirst
204-
items[:] = previously_failed + previously_passed
205-
206-
noun = (
207-
"failure" if self._previously_failed_count == 1 else "failures"
208-
)
209-
suffix = " first" if self.config.getoption("failedfirst") else ""
210-
self._report_status = "rerun previous {count} {noun}{suffix}".format(
211-
count=self._previously_failed_count, suffix=suffix, noun=noun
212-
)
192+
previously_passed.append(item)
193+
self._previously_failed_count = len(previously_failed)
194+
195+
if not previously_failed:
196+
# Running a subset of all tests with recorded failures
197+
# only outside of it.
198+
self._report_status = "%d known failures not in selected tests" % (
199+
len(self.lastfailed),
200+
)
213201
else:
214-
self._report_status = "no previously failed tests, "
215-
if self.config.getoption("last_failed_no_failures") == "none":
216-
self._report_status += "deselecting all items."
217-
config.hook.pytest_deselected(items=items)
218-
items[:] = []
219-
else:
220-
self._report_status += "not deselecting items."
202+
if self.config.getoption("lf"):
203+
items[:] = previously_failed
204+
config.hook.pytest_deselected(items=previously_passed)
205+
else: # --failedfirst
206+
items[:] = previously_failed + previously_passed
207+
208+
noun = "failure" if self._previously_failed_count == 1 else "failures"
209+
suffix = " first" if self.config.getoption("failedfirst") else ""
210+
self._report_status = "rerun previous {count} {noun}{suffix}".format(
211+
count=self._previously_failed_count, suffix=suffix, noun=noun
212+
)
213+
else:
214+
self._report_status = "no previously failed tests, "
215+
if self.config.getoption("last_failed_no_failures") == "none":
216+
self._report_status += "deselecting all items."
217+
config.hook.pytest_deselected(items=items)
218+
items[:] = []
219+
else:
220+
self._report_status += "not deselecting items."
221221

222222
def pytest_sessionfinish(self, session):
223223
config = self.config

src/_pytest/config/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ def parse_hookimpl_opts(self, plugin, name):
282282
known_marks = {m.name for m in getattr(method, "pytestmark", [])}
283283

284284
for name in ("tryfirst", "trylast", "optionalhook", "hookwrapper"):
285-
286285
opts.setdefault(name, hasattr(method, name) or name in known_marks)
287286
return opts
288287

src/_pytest/hookspec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def pytest_collectreport(report):
227227

228228

229229
def pytest_deselected(items):
230-
""" called for test items deselected by keyword. """
230+
""" called for test items deselected, e.g. by keyword. """
231231

232232

233233
@hookspec(firstresult=True)

src/_pytest/mark/structures.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def __getattr__(self, name):
304304
for line in self._config.getini("markers"):
305305
# example lines: "skipif(condition): skip the given test if..."
306306
# or "hypothesis: tests which use Hypothesis", so to get the
307-
# marker name we we split on both `:` and `(`.
307+
# marker name we split on both `:` and `(`.
308308
marker = line.split(":")[0].split("(")[0].strip()
309309
self._markers.add(marker)
310310

src/_pytest/terminal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,10 @@ def pytest_runtest_logfinish(self, nodeid):
453453
progress_length = len(" [100%]")
454454

455455
self._progress_nodeids_reported.add(nodeid)
456-
last_item = (
456+
is_last_item = (
457457
len(self._progress_nodeids_reported) == self._session.testscollected
458458
)
459-
if last_item:
459+
if is_last_item:
460460
self._write_progress_information_filling_space()
461461
else:
462462
w = self._width_of_current_line

0 commit comments

Comments
 (0)