Skip to content

"Fix test_examples on Python 3.14" breaks Python 3.12Β #192

@Aleksanaa

Description

@Aleksanaa

The following error occurs after patching be30d9a:

python312: 3.12.12
pytest-subprocess: 1.5.3 (with said commit as patch)

=================================== FAILURES ===================================
________________________ test_universal_newlines[False] ________________________

unraisable = UnraisableHookArgs(exc_type=<class 'ResourceWarning'>, exc_value=ResourceWarning("unclosed file <_io.FileIO name=14 mode='rb' closefd=True>"), exc_traceback=<traceback object at 0x7ffff5049c80>, err_msg=None, object=<_io.FileIO [closed]>)

    def unraisable_hook(
        unraisable: sys.UnraisableHookArgs,
        /,
        *,
        append: Callable[[UnraisableMeta | BaseException], object],
    ) -> None:
        try:
            # we need to compute these strings here as they might change after
            # the unraisablehook finishes and before the metadata object is
            # collected by a pytest hook
            err_msg = (
                "Exception ignored in" if unraisable.err_msg is None else unraisable.err_msg
            )
            summary = f"{err_msg}: {unraisable.object!r}"
            traceback_message = "\n\n" + "".join(
                traceback.format_exception(
                    unraisable.exc_type,
                    unraisable.exc_value,
                    unraisable.exc_traceback,
                )
            )
>           tracemalloc_tb = "\n" + tracemalloc_message(unraisable.object)
                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/unraisableexception.py:123: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

source = <_io.FileIO [closed]>

    def tracemalloc_message(source: object) -> str:
        if source is None:
            return ""
    
        try:
            import tracemalloc
        except ImportError:
            return ""
    
>       tb = tracemalloc.get_object_traceback(source)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
E       AttributeError: partially initialized module 'tracemalloc' has no attribute 'get_object_traceback' (most likely due to a circular import). Did you mean: '_get_object_traceback'?

/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/tracemalloc.py:13: AttributeError

The above exception was the direct cause of the following exception:

cls = <class '_pytest.runner.CallInfo'>
func = <function call_and_report.<locals>.<lambda> at 0x7ffff505dd00>
when = 'call'
reraise = (<class '_pytest.outcomes.Exit'>, <class 'KeyboardInterrupt'>)

    @classmethod
    def from_call(
        cls,
        func: Callable[[], TResult],
        when: Literal["collect", "setup", "call", "teardown"],
        reraise: type[BaseException] | tuple[type[BaseException], ...] | None = None,
    ) -> CallInfo[TResult]:
        """Call func, wrapping the result in a CallInfo.
    
        :param func:
            The function to call. Called without arguments.
        :type func: Callable[[], _pytest.runner.TResult]
        :param when:
            The phase in which the function is called.
        :param reraise:
            Exception or exceptions that shall propagate if raised by the
            function, instead of being wrapped in the CallInfo.
        """
        excinfo = None
        instant = timing.Instant()
        try:
>           result: TResult | None = func()
                                     ^^^^^^

/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/runner.py:344: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/runner.py:246: in <lambda>
    lambda: runtest_hook(item=item, **kwds), when=when, reraise=reraise
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/nix/store/4kjkvw24wfnx4qb1ij108c46j1c3jiri-python3.12-pluggy-1.6.0/lib/python3.12/site-packages/pluggy/_hooks.py:512: in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/nix/store/4kjkvw24wfnx4qb1ij108c46j1c3jiri-python3.12-pluggy-1.6.0/lib/python3.12/site-packages/pluggy/_manager.py:120: in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/logging.py:850: in pytest_runtest_call
    yield
/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/capture.py:900: in pytest_runtest_call
    return (yield)
            ^^^^^
/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/skipping.py:263: in pytest_runtest_call
    return (yield)
            ^^^^^
/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/unraisableexception.py:158: in pytest_runtest_call
    collect_unraisable(item.config)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

config = <_pytest.config.Config object at 0x7ffff7303e60>

    def collect_unraisable(config: Config) -> None:
        pop_unraisable = config.stash[unraisable_exceptions].pop
        errors: list[pytest.PytestUnraisableExceptionWarning | RuntimeError] = []
        meta = None
        hook_error = None
        try:
            while True:
                try:
                    meta = pop_unraisable()
                except IndexError:
                    break
    
                if isinstance(meta, BaseException):
                    hook_error = RuntimeError("Failed to process unraisable exception")
                    hook_error.__cause__ = meta
                    errors.append(hook_error)
                    continue
    
                msg = meta.msg
                try:
                    warnings.warn(pytest.PytestUnraisableExceptionWarning(msg))
                except pytest.PytestUnraisableExceptionWarning as e:
                    # This except happens when the warning is treated as an error (e.g. `-Werror`).
                    if meta.exc_value is not None:
                        # Exceptions have a better way to show the traceback, but
                        # warnings do not, so hide the traceback from the msg and
                        # set the cause so the traceback shows up in the right place.
                        e.args = (meta.cause_msg,)
                        e.__cause__ = meta.exc_value
                    errors.append(e)
    
            if len(errors) == 1:
>               raise errors[0]
E               RuntimeError: Failed to process unraisable exception

/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/unraisableexception.py:79: RuntimeError
----------------------------- Captured stderr call -----------------------------
Exception ignored in sys.unraisablehook: functools.partial(<function unraisable_hook at 0x7ffff656fc40>, append=<built-in method append of collections.deque object at 0x7ffff5ac49a0>)
Traceback (most recent call last):
  File "/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/unraisableexception.py", line 123, in unraisable_hook
    tracemalloc_tb = "\n" + tracemalloc_message(unraisable.object)
                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/nix/store/cnh9qzgxz2bmn6nzkg7asizmsf6qvjvr-python3.12-pytest-8.4.2/lib/python3.12/site-packages/_pytest/tracemalloc.py", line 13, in tracemalloc_message
    tb = tracemalloc.get_object_traceback(source)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: partially initialized module 'tracemalloc' has no attribute 'get_object_traceback' (most likely due to a circular import)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions