Skip to content
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

Any hints as to how to override the OutputChecker #223

Open
matthew-brett opened this issue Sep 24, 2023 · 9 comments
Open

Any hints as to how to override the OutputChecker #223

matthew-brett opened this issue Sep 24, 2023 · 9 comments
Labels

Comments

@matthew-brett
Copy link
Contributor

We (over at https://github.com/nipy/nipy) have a customized doctest OutputChecker class for a few new directives - https://github.com/matthew-brett/nipy/blob/pytest/nipy/conftest.py#L152

I have tried to apply this output checker by monkey-patching doctest in conftest.py:

doctest.OutputChecker = NipyOutputChecker

I can see, with a debug test in a .py file, that shows me that, when I get to the doctest, doctest.OutputChecker is my checker.

https://github.com/matthew-brett/nipy/blob/pytest/nipy/algorithms/statistics/formula/formulae.py#L95

But the checkers check_output never gets called.

I wondered idly whether this is because y'all enforce your OutputChecker in DoctestModulePlus:

https://github.com/scientific-python/pytest-doctestplus/blob/main/pytest_doctestplus/plugin.py#L268

What is the best way to plumb in my OutputChecker, when using pytest-doctestplus?

@pllim pllim added the question label Sep 25, 2023
@pllim
Copy link
Contributor

pllim commented Sep 25, 2023

You mean, you want to use your own custom doctest directives on top of what doctestplus provides?

@pllim
Copy link
Contributor

pllim commented Sep 25, 2023

I wonder if what you have can be merged into this package (unless they duplicate existing functionality). Though the sympy one is tricky unless you can make it optional (i.e., enabled only if sympy is installed).

@matthew-brett
Copy link
Contributor Author

Yes - exactly - in my case I want to extend the options available to the doctest processing - and to do that - I need to change the OutputChecker - just for reference for anyone who doesn't knowdoctest - this stuff:

https://docs.python.org/3/library/doctest.html#doctest.DocTestRunner

I can certainly make a PR with the code we have, and make sympy optional - but it would be very good to have some extension mechanism such that you can plumb such things without modifying the doctestplus code.

@pllim
Copy link
Contributor

pllim commented Sep 25, 2023

Hmm, I am not expert in that, so I'll defer to @bsipocz and @saimn on this.

@matthew-brett
Copy link
Contributor Author

I see that it would be moderately difficult to do - but it would be very useful.

@saimn
Copy link
Contributor

saimn commented Sep 26, 2023

Not sure if there is a good way to do it, given the way it's done currently 😬
I guess you should have a look at doctest's code to see why we need both
https://github.com/scientific-python/pytest-doctestplus/blob/main/pytest_doctestplus/plugin.py#L268 and
https://github.com/scientific-python/pytest-doctestplus/blob/main/pytest_doctestplus/plugin.py#L198
(or maybe we don't need both).

@ev-br
Copy link

ev-br commented Mar 2, 2024

Is this still relevant @matthew-brett ?
I need to make DoctestParser pluggable in scipy-doctest, and started with OutputChecker since it's easier:
scipy/scipy_doctest#141

@matthew-brett
Copy link
Contributor Author

I spent some time trying to weave my way into the depths of monkey-patching, before giving up, and accepting the constraints of doctest-plus for doctesting. So - yes - still relevant - but I don't have any great wisdom on how the output checking should best be extended here.

@ev-br
Copy link

ev-br commented Mar 2, 2024

Not sure how to do it with pytest-doctestplus either. Do you feel like giving an alternative a go?
If you do, we can take it to the tracker https://github.com/ev-br/scpdt --- for context see scipy/scipy#20127 and https://mail.python.org/archives/list/[email protected]/thread/XH5RDJ5GZRRBP3UAQGWNWMH6P3KYZAUA/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants