Skip to content

Tests always skipped when dependency version is present #318

@KostaIlic2

Description

@KostaIlic2

__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:

  1. Create virtual environment: python -m venv .venv
  2. Install dependencies: .\.venv\Scripts\pip.exe install -e .
  3. Show NumPy version: .\.venv\Scripts\pip.exe show numpy
  4. Read the output to verify NumPy >= 2.0 is installed.
  5. Run doctest: .\.venv\Scripts\python.exe -m pytest demo.py --doctest-modules -v
  6. 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')
  7. Upgrade pytest-doctestplus to 1.6.0 and run the test again, following the steps
    mentioned above.
  8. 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"

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions