Skip to content

Commit 7775e49

Browse files
committed
Further tweaks from code review
1 parent c4876c7 commit 7775e49

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ build-backend = "setuptools.build_meta"
1010
write_to = "src/_pytest/_version.py"
1111

1212
[tool.pytest.ini_options]
13-
#minversion = "2.0"
13+
minversion = "2.0"
1414
addopts = "-rfEX -p pytester --strict-markers"
1515
python_files = ["test_*.py", "*_test.py", "testing/python/*.py"]
1616
python_classes = ["Test", "Acceptance"]

src/_pytest/recwarn.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,20 +206,17 @@ def __len__(self) -> int:
206206
return len(self._list)
207207

208208
def pop(self, cls: Type[Warning] = Warning) -> "warnings.WarningMessage":
209-
"""Pop the first recorded warning which is an instance of ``cls``.
210-
211-
But not an instance of a child class of any other match.
209+
"""Pop the first recorded warning which is an instance of ``cls``,
210+
but not an instance of a child class of any other match.
212211
Raises ``AssertionError`` if there is no match.
213-
214212
"""
215-
216-
best_idx = None
213+
best_idx: Optional[int] = None
217214
for i, w in enumerate(self._list):
218215
if w.category == cls:
219216
return self._list.pop(i) # exact match, stop looking
220217
if issubclass(w.category, cls) and (
221218
best_idx is None
222-
or not issubclass(w.category, self._list[best_idx].category) # type: ignore[unreachable]
219+
or not issubclass(w.category, self._list[best_idx].category)
223220
):
224221
best_idx = i
225222
if best_idx is not None:

testing/test_recwarn.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def raise_warnings_from_list(_warnings: List[Type[Warning]]):
5454
for warn in _warnings:
5555
warnings.warn(f"Warning {warn().__repr__()}", warn)
5656

57-
def test_pop(self):
57+
def test_pop_finds_exact_match(self):
5858
with pytest.warns((self.ParentWarning, self.ChildWarning)) as record:
5959
self.raise_warnings_from_list(
6060
[self.ChildWarning, self.ParentWarning, self.ChildOfChildWarning]
@@ -64,13 +64,13 @@ def test_pop(self):
6464
_warn = record.pop(self.ParentWarning)
6565
assert _warn.category is self.ParentWarning
6666

67-
def test_pop_raises(self):
67+
def test_pop_raises_if_no_match(self):
6868
with pytest.raises(AssertionError):
6969
with pytest.warns(self.ParentWarning) as record:
7070
self.raise_warnings_from_list([self.ParentWarning])
7171
record.pop(self.ChildOfChildWarning)
7272

73-
def test_pop_most_recent(self):
73+
def test_pop_finds_best_inexact_match(self):
7474
with pytest.warns(self.ParentWarning) as record:
7575
self.raise_warnings_from_list(
7676
[self.ChildOfChildWarning, self.ChildWarning, self.ChildOfChildWarning]

0 commit comments

Comments
 (0)