Skip to content

pytest-9.2.0 with pytest-asyncio, -Werror, and empty directory, fails with unrelated deprecation warning and incorrect exit code. #15280

Closed

Description

When pytest-9.2.0 is used with pytest-asyncio, -Werror and an empty directory temp:

  • It generates deprecation warnings.
  • The exit code is 3 "Internal error happened while executing tests", when it should be 5 "No tests were collected".

I guess this could mean that pytest-asyncio needs to be updated to match pytest-9.2.0?

To reproduce:

> pip install pytest pytest-asyncio
...
Successfully installed pytest-9.2.0 pytest-asyncio-1.4.1

> pytest -Werror temp
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File ".../lib/python3.14/site-packages/_pytest/main.py", line 329, in wrap_session
INTERNALERROR>     config._do_configure()
INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~^^
INTERNALERROR>   File ".../lib/python3.14/site-packages/_pytest/config/__init__.py", line 1370, in _do_configure
INTERNALERROR>     self.hook.pytest_configure.call_historic(kwargs=dict(config=self))
INTERNALERROR>     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File ".../lib/python3.14/site-packages/pluggy/_caller.py", line 222, in call_historic
INTERNALERROR>     res = self._hookexec(self.name, self._hookimpls.copy(), kwargs, False)
INTERNALERROR>   File ".../lib/python3.14/site-packages/pluggy/_manager.py", line 183, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>            ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR>   File ".../lib/python3.14/site-packages/pluggy/_execution.py", line 195, in _multicall
INTERNALERROR>     raise exception
INTERNALERROR>   File ".../lib/python3.14/site-packages/pluggy/_execution.py", line 147, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File ".../lib/python3.14/site-packages/pytest_asyncio/plugin.py", line 299, in pytest_configure
INTERNALERROR>     warnings.warn(PytestDeprecationWarning(_DEFAULT_FIXTURE_LOOP_SCOPE_UNSET))
INTERNALERROR>     ~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
INTERNALERROR> pytest.PytestDeprecationWarning: The configuration option "asyncio_default_fixture_loop_scope" is unset.
INTERNALERROR> The event loop scope for asynchronous fixtures will default to the "fixture" caching scope. Future versions of pytest-asyncio will default the loop scope for asynchronous fixtures to "function" scope. Set the default fixture loop scope explicitly in order to avoid unexpected behavior in the future. Valid fixture loop scopes are: "function", "class", "module", "package", "session"

> echo $?
3

>

Without pytest-asyncio, pytest-9.2.0 behaves as expected:

> pip uninstall pytest-asyncio
...
  Successfully uninstalled pytest-asyncio-1.4.1

> pytest -Werror temp
======================================================================== test session starts ========================================================================
platform linux -- Python 3.14.8, pytest-9.2.0, pluggy-1.7.0
rootdir: ...
collected 0 items                                                                                                                                                   

======================================================================= no tests ran in 0.71s =======================================================================

> echo $?
5
> 

Similarly with previous release pytest-9.1.1 and pytest-asyncio:

> pip install pytest==9.1.1 pytest-asyncio
...
Successfully installed pytest-9.1.1 pytest-asyncio-1.4.1

> pytest -Werror temp
==================================================================================================== test session starts ====================================================================================================
platform linux -- Python 3.14.8, pytest-9.1.1, pluggy-1.7.0
rootdir: ...
plugins: platformdirs-4.13.5, asyncio-1.4.0, anyio-4.15.1
asyncio: mode=Mode.STRICT, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collected 0 items                                                                                                                                                                                                           

=================================================================================================== no tests ran in 0.76s ===================================================================================================

> echo $?
5

>

Installed packages:

> pip list
iniconfig      2.3.1
packaging      26.3
pip            26.0.1
pluggy         1.7.0
Pygments       2.21.0
pytest         9.2.0
pytest-asyncio 1.4.1
>

Operating system versions

> uname -a
Linux ... 6.19.13+deb14-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.19.13-1 (2026-04-18) x86_64 GNU/Linux
> 

Activity

  1. bluetech commented on Oct 28, 2026

    @bluetech
    Member

    Yes, this is do to this change (note from the changelog):

    #12697: Warnings emitted while importing plugins through -p, PYTEST_PLUGINS, or entry point autoloading are now captured, filtered, and reported like other warnings.

    It does seem a bit unfortunate that a plain pytest + pytest-asyncio now "crashes" with -Werror, however -Werror is kind of requesting this behavior.

    I'm not sure there's much we can do here. I suggest setting asyncio_default_fixture_loop_scope in your configuration which will resolve the deprecation.

  2. julian-smith-artifex-com commented on Oct 28, 2026

    @julian-smith-artifex-com
    Author

    @bluetech Many thanks for the swift response.

    pytest -o asyncio_default_fixture_loop_scope=function avoids the problem for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions