pytest-dev / pytest-dev/pytest

`pytest` does not work with `PYTHON_LAZY_IMPORTS=all`

Open
#14,632 1 comment 3 reactions 2 assignees View on GitHub

@RonnyPfannschmidt is already working on this.

Since Jun 21, 2026.

Dominant language
Python
Stars
14.5k
Forks
3.4k
Avg merge
2d 9h
Merged PRs (30d)
35

Description

Python version: 3.15.0b2+dev
Pytest version: 9.1.1

PYTHON_LAZY_IMPORTS=all pytest --help produces:

Traceback (most recent call last):
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/config/__init__.py", line 50, in <module>
    from .exceptions import UsageError as UsageError
ImportError: lazy import of '_pytest.config.exceptions.UsageError' raised an exception during resolution

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

Traceback (most recent call last):
  File "/Users/sobolev/Desktop/msgspec/.venv/bin/pytest", line 10, in <module>
    sys.exit(console_main())
             ~~~~~~~~~~~~^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/config/__init__.py", line 223, in console_main
    code = main()
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/config/__init__.py", line 193, in main
    config = _prepareconfig(new_args, plugins)
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/config/__init__.py", line 361, in _prepareconfig
    config: Config = pluginmanager.hook.pytest_cmdline_parse(
                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
        pluginmanager=pluginmanager, args=args
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/pluggy/_hooks.py", line 512, in __call__
    return self._hookexec(self.name, self._hookimpls.copy(), kwargs, firstresult)
           ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/pluggy/_manager.py", line 120, in _hookexec
    return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
           ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/pluggy/_callers.py", line 167, in _multicall
    raise exception
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/pluggy/_callers.py", line 139, in _multicall
    teardown.throw(exception)
    ~~~~~~~~~~~~~~^^^^^^^^^^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/helpconfig.py", line 124, in pytest_cmdline_parse
    config = yield
             ^^^^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/pluggy/_callers.py", line 121, in _multicall
    res = hook_impl.function(*args)
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/config/__init__.py", line 1193, in pytest_cmdline_parse
    except UsageError:
           ^^^^^^^^^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/assertion/rewrite.py", line 111, in find_spec
    if self._early_rewrite_bailout(name, state):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/assertion/rewrite.py", line 229, in _early_rewrite_bailout
    if fnmatch_ex(pat, path):
       ~~~~~~~~~~^^^^^^^^^^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/pathlib.py", line 452, in fnmatch_ex
    return fnmatch.fnmatch(name, pattern)
           ^^^^^^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/assertion/rewrite.py", line 111, in find_spec
    if self._early_rewrite_bailout(name, state):
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/assertion/rewrite.py", line 229, in _early_rewrite_bailout
    if fnmatch_ex(pat, path):
       ~~~~~~~~~~^^^^^^^^^^^
  File "/Users/sobolev/Desktop/msgspec/.venv/lib/python3.15/site-packages/_pytest/pathlib.py", line 452, in fnmatch_ex
    return fnmatch.fnmatch(name, pattern)
           ^^^^^^^
ImportCycleError: cannot import name 'fnmatch' (most likely due to a circular import)                

The same happens for all other invokations.

Contributor guide

Open the contributing guide

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.