-
Notifications
You must be signed in to change notification settings - Fork 43
Open
Labels
Description
__doctest_requires__ causes tests to be skipped whenever a dependency version requirement is present, even if the dependency is present and meets the requirement.
The code was behaving correctly in 1.5.0. The bug was present in 1.6.0. The bug is still present in 1.7.0.
To reproduce, save code fragments shown below as demo.py and pyproject.toml into an empty project root directory, then run the following commands from that directory:
- Create virtual environment:
python -m venv .venv - Install dependencies:
.\.venv\Scripts\pip.exe install -e . - Show NumPy version:
.\.venv\Scripts\pip.exe show numpy - Read the output to verify NumPy >= 2.0 is installed.
- Run
doctest: .\.venv\Scripts\python.exe -m pytest demo.py --doctest-modules -v - Observe the output depending on the version of pytest-doctestplus:
1.5.0:demo.py::demo.my_function PASSED
1.6.0:demo.py::demo.my_function SKIPPED (could not import 'numpy>=2.0': No module named 'numpy>=2')
1.7.0:demo.py::demo.my_function SKIPPED (could not import 'numpy>=2.0': No module named 'numpy>=2') - Upgrade pytest-doctestplus to 1.6.0 and run the test again, following the steps
mentioned above. - Upgrade pytest-doctestplus to 1.7.0 and run the test again, following the steps
mentioned above.
#demo.py
__doctest_requires__ = {("my_function",): ["numpy>=2.0"]}
def my_function():
"""Simple function to demonstrate the bug.
>>> import numpy as np
>>> np.array([1, 2, 3])
array([1, 2, 3])
"""
pass#pyproject.toml
[project]
name = "pytest-doctestplus-bug-demo"
version = "0.1.0"
description = "Demonstrates pytest-doctestplus 1.7.0 bug with version constraints"
requires-python = ">=3.9"
dependencies = [
"numpy>=2.0",
"pytest-doctestplus==1.5.0",
"pytest>=7.0",
]
[build-system]
requires = ["setuptools>=45", "wheel"]
build-backend = "setuptools.build_meta"
[tool.pytest.ini_options]
addopts = "--doctest-modules --doctest-plus"