pytest-dev/pytest · warning · Skipped
module has __version__ , required is
Error message
module {modname!r} has __version__ {verattr!r}, required is: {minversion!r} What it means
Raised by the import/skip helper (pytest.importorskip with minversion) when the imported module's __version__ is missing or older than the required minversion. At lines 276-285 the helper reads __version__ via getattr; if it is None or Version(verattr) < Version(minversion), a Skipped outcome is raised with allow_module_level=True so the whole module is skipped rather than failed. This is an outcome, not a hard error, used for graceful degradation.
Solutions
- Upgrade the dependency to meet minversion: pip install -U <package>.
- Lower or correct the minversion argument to match the installed version.
- Ensure the module exposes __version__ (set it in the package __init__).
- If the version is correct, verify the minversion format is PEP 440 compliant.
Example fix
// before
mod = pytest.importorskip('numpy', minversion='2.0')
// after
mod = pytest.importorskip('numpy', minversion='1.20') Defensive patterns
Strategy: validation
Validate before calling
import packaging.version
ver = getattr(__import__('numpy'), '__version__', None)
if ver is None or packaging.version.Version(ver) < packaging.version.Version('1.20'):
pytest.skip('numpy too old') Type guard
def _version_ok(modname, minversion) -> bool:
import packaging.version
ver = getattr(__import__(modname), '__version__', None)
return ver is not None and packaging.version.Version(ver) >= packaging.version.Version(minversion) Prevention
- Pin compatible dependency versions in requirements.
- Ensure packages expose a PEP 440 __version__.
When it happens
Trigger: pytest.importorskip('numpy', minversion='1.20') when numpy is older; module lacks __version__ entirely; minversion string malformed so comparison places it above the installed version.
Common situations: CI environments with pinned older dependency versions; packages that do not set __version__; typos in the minversion argument; version string formats that packaging.Version mis-parses.
Related errors
- expected string as 'msg' parameter, got ' '…
- absolute tolerance can't be NaN.
- absolute tolerance can't be negative
- absolute tolerance for a scalar value must be an int, float…
- alias conflicts with existing configuration option
AI-assisted analysis of pytest-dev/pytest@0d6fbdeffa (2026-08-11).
Data as JSON: /api/errors/93c3b228477f5c24.
Report an issue: GitHub.
Appendix: source
Thrown at src/_pytest/outcomes.py:282
importlib.import_module(modname)
except exc_type as exc:
# Do not raise or issue warnings inside the catch_warnings() block.
if reason is None:
reason = f"could not import {modname!r}: {exc}"
skipped = Skipped(reason, allow_module_level=True)
if skipped:
raise skipped
mod = sys.modules[modname]
if minversion is None:
return mod
verattr = getattr(mod, "__version__", None)
if minversion is not None:
# Imported lazily to improve start-up time.
from packaging.version import Version
if verattr is None or Version(verattr) < Version(minversion):
raise Skipped(
f"module {modname!r} has __version__ {verattr!r}, required is: {minversion!r}",
allow_module_level=True,
)
return mod
View on GitHub (pinned to 0d6fbdeffa)