| 330 | assert str(record[1].message) == "runtime" |
| 331 | |
| 332 | def test_record_by_subclass(self) -> None: |
| 333 | with pytest.warns(Warning) as record: |
| 334 | warnings.warn("user", UserWarning) |
| 335 | warnings.warn("runtime", RuntimeWarning) |
| 336 | |
| 337 | assert len(record) == 2 |
| 338 | assert str(record[0].message) == "user" |
| 339 | assert str(record[1].message) == "runtime" |
| 340 | |
| 341 | class MyUserWarning(UserWarning): |
| 342 | pass |
| 343 | |
| 344 | class MyRuntimeWarning(RuntimeWarning): |
| 345 | pass |
| 346 | |
| 347 | with pytest.warns((UserWarning, RuntimeWarning)) as record: |
| 348 | warnings.warn("user", MyUserWarning) |
| 349 | warnings.warn("runtime", MyRuntimeWarning) |
| 350 | |
| 351 | assert len(record) == 2 |
| 352 | assert str(record[0].message) == "user" |
| 353 | assert str(record[1].message) == "runtime" |
| 354 | |
| 355 | def test_double_test(self, pytester: Pytester) -> None: |
| 356 | """If a test is run again, the warning should still be raised""" |