pytest-dev / pytest-dev/pytest-forked

`ResourceWarning`/`PytestUnraisableExceptionWarning` with version 1.7.5

Open Beginner friendly
#106 0 comments 0 reactions 0 assignees View on GitHub

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:

https://github.com/pytest-dev/pytest-forked/blob/3e8450ba17b184b7070c7e93de140db2f87d9239/src/pytest_forked/__init__.py#L101-L106

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.