pytest-dev / pytest-dev/pytest
filterwarnings doesn't deal with ExceptionGroups of pytest.PytestUnraisableExceptionWarning
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 14.5k
- Forks
- 3.4k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 35
Description
I have a test annotated with @pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning") because I depend on a library I know will likely leak. However, I noticed this doesn't work if there are 2 leaks at the same time:
| File "<python venv>/site-packages/_pytest/unraisableexception.py", line 95, in cleanup
| collect_unraisable(config)
| File "<python venv>/site-packages/_pytest/unraisableexception.py", line 81, in collect_unraisable
| raise ExceptionGroup("multiple unraisable exception warnings", errors)
| ExceptionGroup: multiple unraisable exception warnings (2 sub-exceptions)
+-+---------------- 1 ----------------
| Traceback (most recent call last):
| File "<python venv>/site-packages/_pytest/unraisableexception.py", line 33, in gc_collect_harder
| gc.collect()
| ResourceWarning: unclosed <socket.socket fd=57, family=2, type=1, proto=6, laddr=('ip1', ...), raddr=('ip2', ...)>
|
| The above exception was the direct cause of the following exception:
|
| Traceback (most recent call last):
| File "<python venv>/site-packages/_pytest/unraisableexception.py", line 67, in collect_unraisable
| warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
| pytest.PytestUnraisableExceptionWarning: Exception ignored in: <socket.socket fd=57, family=2, type=1, proto=6, laddr=('ip1', ...), raddr=('ip2', ...)>
Enable tracemalloc to get traceback where the object was allocated.
See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
+---------------- 2 ----------------
| Traceback (most recent call last):
| File "<python venv>lib/python3.11/asyncio/selector_events.py", line 868, in __del__
| _warn(f"unclosed transport {self!r}", ResourceWarning, source=self)
| ResourceWarning: unclosed transport <_SelectorSocketTransport fd=57>
|
| The above exception was the direct cause of the following exception:
|
| Traceback (most recent call last):
| File "<python venv>/site-packages/_pytest/unraisableexception.py", line 67, in collect_unraisable
| warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
| pytest.PytestUnraisableExceptionWarning: Exception ignored in: <function _SelectorTransport.__del__ at 0x...>
Enable tracemalloc to get traceback where the object was allocated.
See https://docs.pytest.org/en/stable/how-to/capture-warnings.html#resource-warnings for more info.
+------------------------------------
It would be nice if filterwarnings could deal with this condition easily -- like filter out the matching sub exceptions. Maybe it already can? I haven't seen much written on the internet about it...
pytest 8.4.2, python 3.11
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with _pytest/unraisableexception.py, especially collect_unraisable, and reproduce the report using two unraisable warnings with the pytest.mark.filterwarnings marker. Compare single-warning and ExceptionGroup behavior; done means matching PytestUnraisableExceptionWarning subexceptions are filtered without suppressing unrelated warnings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100