Repository: pytest-dev/pytest-asyncio

Issue #729: pytest-asyncio-0.23.2 loads packages more eagerly
Created: 2023-12-24T11:01:13Z
In our case it is actually causing issues. In short, we have Python files in our tests dir that should only be loaded in a specific context. I'll elaborate in more detail below. We could probably work around it if we need to, but for now we have pinned pytest-asyncio to the previous version until this discussion reaches a conclusion.
Our specifix use case: we are developing a Python project with a plugin system. Put simply, these plugins are Python packages that register themselves at load time. They are expected to be loaded by a custom importlib finder/loader and they do not work as standalone package.
Since this plugin system is an integral part of the application we're developing, we test their behavior thoroughly. Therefore we have a bunch of these plugin "packages" as resources underneath our tests directory. They are meant as nothing more than data: our application will find and load them when appropriate. They will raise an error when loaded as a standalone package, which pytest v0.23 now does.
Originally posted by @sanderr in #713 (comment)

Duplicate issue #739: Startup failure on Windows with Version 0.23.3
Created: 2024-01-05T02:10:04Z
It appears that #701 has resurfaced with 0.23.3.
https://github.com/ipython/ipykernel/actions/runs/7416261764/job/20180923947

============================= test session starts =============================
platform win32 -- Python 3.9.13, pytest-7.4.4, pluggy-1.3.0 -- C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\Scripts\python.exe
cachedir: .pytest_cache
rootdir: D:\a\ipykernel\ipykernel
configfile: pyproject.toml
testpaths: tests, tests/inprocess
plugins: flaky-3.7.0, asyncio-0.23.3, cov-4.1.0, timeout-2.2.0
asyncio: mode=auto
timeout: 300.0s
timeout method: thread
timeout func_only: False
collecting ... collected 21 items
INTERNALERROR> Traceback (most recent call last):
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\main.py", line 271, in wrap_session
INTERNALERROR>     session.exitstatus = doit(config, session) or 0
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\main.py", line 324, in _main
INTERNALERROR>     config.hook.pytest_collection(session=session)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\pluggy\_hooks.py", line 493, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\pluggy\_manager.py", line 115, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\pluggy\_callers.py", line 152, in _multicall
INTERNALERROR>     return outcome.get_result()
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\pluggy\_result.py", line 114, in get_result
INTERNALERROR>     raise exc.with_traceback(exc.__traceback__)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\pluggy\_callers.py", line 77, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\main.py", line 335, in pytest_collection
INTERNALERROR>     session.perform_collect()
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\main.py", line 675, in perform_collect
INTERNALERROR>     self.items.extend(self.genitems(node))
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\main.py", line 845, in genitems
INTERNALERROR>     yield from self.genitems(subnode)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\main.py", line 842, in genitems
INTERNALERROR>     rep = collect_one_node(node)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\runner.py", line 546, in collect_one_node
INTERNALERROR>     ihook.pytest_collectstart(collector=collector)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\pluggy\_hooks.py", line 493, in __call__
INTERNALERROR>     return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\pluggy\_manager.py", line 115, in _hookexec
INTERNALERROR>     return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\pluggy\_callers.py", line 113, in _multicall
INTERNALERROR>     raise exception.with_traceback(exception.__traceback__)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\pluggy\_callers.py", line 77, in _multicall
INTERNALERROR>     res = hook_impl.function(*args)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\pytest_asyncio\plugin.py", line 626, in pytest_collectstart
INTERNALERROR>     pyobject = collector.obj
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\python.py", line 310, in obj
INTERNALERROR>     self._obj = obj = self._getobj()
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\python.py", line 528, in _getobj
INTERNALERROR>     return self._importtestmodule()
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\python.py", line 617, in _importtestmodule
INTERNALERROR>     mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\pathlib.py", line 567, in import_path
INTERNALERROR>     importlib.import_module(module_name)
INTERNALERROR>   File "C:\hostedtoolcache\windows\Python\3.9.13\x64\lib\importlib\__init__.py", line 127, in import_module
INTERNALERROR>     return _bootstrap._gcd_import(name[level:], package, level)
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
INTERNALERROR>   File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\assertion\rewrite.py", line 186, in exec_module
INTERNALERROR>     exec(co, module.__dict__)
INTERNALERROR>   File "D:\a\ipykernel\ipykernel\tests\test_embed_kernel.py", line 26, in <module>
INTERNALERROR>     pytest.skip("skipping tests on windows", allow_module_level=True)
INTERNALERROR>   File "C:\Users\runneradmin\AppData\Local\hatch\env\virtual\ipykernel\nS5Qyasy\cov.qt5\lib\site-packages\_pytest\outcomes.py", line 179, in skip
INTERNALERROR>     raise Skipped(msg=reason, allow_module_level=allow_module_level)
INTERNALERROR> Skipped: skipping tests on windows

============================= 1 warning in 0.23s ==============================

Closing comment (2024-01-09T17:47:36Z): Based on the traceback, I'd say this is a duplicate of #729. This is the main issue that has been addressed in v0.23.4a0.
I'll close this issue as a duplicate of #729.
I'd appreciate if you could leave feedback in the linked issue whether the pre-release fixes the error you're seeing.