pytest-dev / pytest-dev/pytest-forked
`ResourceWarning`/`PytestUnraisableExceptionWarning` with version 1.7.5
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 83
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
Pytest functions decorated with @pytest.mark.forked that were working fine on version 1.6.0 (previous PyPI release) are now failing on 1.7.5 (full error at the end):
ExceptionGroup: multiple unraisable exception warnings (2 sub-exceptions)
ResourceWarning: unclosed file <_io.TextIOWrapper name='.../stderr' mode='w' encoding='UTF-8'>
I believe it's due to this code which calls flush() without close(), introduced in c33e4e1efad870b3b9aa308e4ec8ac145884c83d:
The test fails with an ExceptionGroup containing two PytestUnraisableExceptionWarning errors, one each for unclosed stdout and stderr temp files.
Full error
============================= test session starts ==============================
platform darwin -- Python 3.14.6, pytest-9.1.1, pluggy-1.6.0
rootdir: …
configfile: pytest.ini
plugins: anyio-4.14.0, forked-1.7.5
collected 1 item
tests/open_browser.py E [100%]
==================================== ERRORS ====================================
________________________ ERROR at setup of pytest_fork _________________________
+ Exception Group Traceback (most recent call last):
| File "…/.venv/lib/python3.14/site-packages/_pytest/runner.py", line 361, in from_call
| result: TResult | None = func()
| ~~~~^^
| File "…/.venv/lib/python3.14/site-packages/_pytest/runner.py", line 250, in <lambda>
| lambda: runtest_hook(item=item, **kwds),
| ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
| File "…/.venv/lib/python3.14/site-packages/pluggy/_hooks.py", line 512, in __call__
| return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
| ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "…/.venv/lib/python3.14/site-packages/pluggy/_manager.py", line 120, in _hookexec
| return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
| ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| File "…/.venv/lib/python3.14/site-packages/pluggy/_callers.py", line 167, in _multicall
| raise exception
| File "…/.venv/lib/python3.14/site-packages/pluggy/_callers.py", line 139, in _multicall
| teardown.throw(exception)
| ~~~~~~~~~~~~~~^^^^^^^^^^^
| File "…/.venv/lib/python3.14/site-packages/_pytest/logging.py", line 858, in pytest_runtest_setup
| yield
| File "…/.venv/lib/python3.14/site-packages/pluggy/_callers.py", line 139, in _multicall
| teardown.throw(exception)
| ~~~~~~~~~~~~~~^^^^^^^^^^^
| File "…/.venv/lib/python3.14/site-packages/_pytest/capture.py", line 895, in pytest_runtest_setup
| return (yield)
| ^^^^^
| File "…/.venv/lib/python3.14/site-packages/pluggy/_callers.py", line 121, in _multicall
| res = hook_impl.function(*args)
| File "…/.venv/lib/python3.14/site-packages/_pytest/unraisableexception.py", line 178, in pytest_runtest_setup
| collect_unraisable(item.config)
| ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
| File "…/.venv/lib/python3.14/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 "…/.venv/lib/python3.14/site-packages/_pytest/capture.py", line 425, in resume
| setattr(sys, self.name, self.tmpfile)
| ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ResourceWarning: unclosed file <_io.TextIOWrapper name='/var/folders/mx/t3rtb4cn7xxfz8w_pcfdffhm0000gn/T/tmpq33e1t7y/stderr' mode='w' encoding='UTF-8'>
|
| The above exception was the direct cause of the following exception:
|
| Traceback (most recent call last):
| File "…/.venv/lib/python3.14/site-packages/_pytest/unraisableexception.py", line 67, in collect_unraisable
| warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
| ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| pytest.PytestUnraisableExceptionWarning: Exception ignored while finalizing file <_io.FileIO name='/var/folders/mx/t3rtb4cn7xxfz8w_pcfdffhm0000gn/T/tmpq33e1t7y/stderr' mode='wb' closefd=True>: None
|
+---------------- 2 ----------------
| Traceback (most recent call last):
| File "…/.venv/lib/python3.14/site-packages/_pytest/capture.py", line 425, in resume
| setattr(sys, self.name, self.tmpfile)
| ~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| ResourceWarning: unclosed file <_io.TextIOWrapper name='/var/folders/mx/t3rtb4cn7xxfz8w_pcfdffhm0000gn/T/tmpq33e1t7y/stdout' mode='w' encoding='UTF-8'>
|
| The above exception was the direct cause of the following exception:
|
| Traceback (most recent call last):
| File "…/.venv/lib/python3.14/site-packages/_pytest/unraisableexception.py", line 67, in collect_unraisable
| warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
| ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| pytest.PytestUnraisableExceptionWarning: Exception ignored while finalizing file <_io.FileIO name='/var/folders/mx/t3rtb4cn7xxfz8w_pcfdffhm0000gn/T/tmpq33e1t7y/stdout' mode='wb' closefd=True>: None
|
+------------------------------------
Contributor guide
No contributing guide indexed for this repository
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 src/pytest_forked/init.py at the cited lines 101-106 and reproduce a pytest function decorated with @pytest.mark.forked on version 1.7.5. Check the handling of stdout and stderr temporary files; done means the forked test completes without unclosed-file ResourceWarning or PytestUnraisableExceptionWarning errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 72/100