Skip to content

Doctestplus adapter #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,8 @@ jobs:
for file in "${test_files[@]}"; do
python -m pytest "${file}" --doctest-modules
done

- name: Demo interoperability with doctestplus
run: |
python -m pip install pytest-doctestplus
python -m pytest scipy_doctest/tests/ -v -k'alt_checker'
53 changes: 53 additions & 0 deletions scipy_doctest/tests/test_pytest_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,56 @@ def func():
result = pytester.inline_run(f, '--doctest-modules')
assert result.ret == pytest.ExitCode.TESTS_FAILED


def test_alt_checker_doctestplus(pytester):
"""Test an alternative Checker, from pytest-doctestplus."""
pytest.importorskip("pytest_doctestplus")

# create a temporary conftest.py file
pytester.makeconftest(
"""
import doctest
from scipy_doctest.conftest import dt_config

# hack!
from pytest_doctestplus.output_checker import OutputChecker as _OutputCheckerImpl

# DTChecker expectes a `config` ctor argument, add it
class PDPChecker(_OutputCheckerImpl):
def __init__(self, config):
super().__init__()

# Register the checker
dt_config.CheckerKlass = PDPChecker
"""
)

# create a temporary pytest test file
src = (
"""
def func():
'''
The doctest below, when run from the command line,
- passes with `pytest --doctest-modules --doctest-plus`, and
- fails without `--doctest-plus`.

We however run this doctest using the PDPChecker, so it picks up
the FLOAT_CMP directive from doctestplus without a command-line switch.

>>> 2/3 # doctest: +FLOAT_CMP
0.666666
'''
pass
"""
)

# run the doctest
f = pytester.makepyfile(src)
result = pytester.inline_run(f, '--doctest-modules')
assert result.ret == pytest.ExitCode.OK

# remove the directive and rerun
src_ = src.replace("# doctest: +FLOAT_CMP", "")
f_ = pytester.makepyfile(src_)
result = pytester.inline_run(f_, '--doctest-modules')
assert result.ret == pytest.ExitCode.TESTS_FAILED