Closed
Description
This appears to have been introduced in 0.23.2 (0.21.x works):
pip3 install pytest pytest-asyncio
- Define the following file (or test)
test_one.py
import asdf # nonexistent module
def test_abc():
pass
pytest --import-mode=importlib
will report no tests run underpytest-asyncio==0.23.2
, but will show the ImportError underpytest-asyncio==0.21.1
. Note that the default import mode (--import-mode=prepend
) does not exhibit this problem.
Output when running under 0.23.2:
(.venv) williamjen@xps-32:~/Documents/import-error-pytest$ cat test_one.py
import asdf
def test_abc():
pass
(.venv) williamjen@xps-32:~/Documents/import-error-pytest$ pytest --import-mode=importlib
============================================================================================== test session starts ==============================================================================================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /home/williamjen/Documents/import-error-pytest
plugins: asyncio-0.23.2
asyncio: mode=strict
collected 0 items
============================================================================================= no tests ran in 0.01s =============================================================================================
(.venv) williamjen@xps-32:~/Documents/import-error-pytest$
Output when running under 0.21.1:
(.venv) williamjen@xps-32:~/Documents/import-error-pytest$ pytest --import-mode=importlib
============================================================================================== test session starts ==============================================================================================
platform linux -- Python 3.10.12, pytest-7.4.3, pluggy-1.3.0
rootdir: /home/williamjen/Documents/import-error-pytest
plugins: asyncio-0.21.1
asyncio: mode=strict
collected 0 items / 1 error
==================================================================================================== ERRORS =====================================================================================================
_________________________________________________________________________________________ ERROR collecting test_one.py __________________________________________________________________________________________
ImportError while importing test module '/home/williamjen/Documents/import-error-pytest/test_one.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
test_one.py:1: in <module>
import asdf
E ModuleNotFoundError: No module named 'asdf'
============================================================================================ short test summary info ============================================================================================
ERROR test_one.py
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
============================================================================
My suspicion is the CollectError
caught in a214c3e since the ImportError appears to be propagated via a CollectError
, but I'm not sure.