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

Why is there testsetup but no testcleanup? #164

Closed
pllim opened this issue Sep 15, 2021 · 7 comments · Fixed by #165
Closed

Why is there testsetup but no testcleanup? #164

pllim opened this issue Sep 15, 2021 · 7 comments · Fixed by #165

Comments

@pllim
Copy link
Contributor

pllim commented Sep 15, 2021

https://github.com/astropy/pytest-doctestplus/blob/16d6d4527439516d5a370b34941e4f1f549268f5/pytest_doctestplus/sphinx/doctestplus.py#L54

There appears to be no support for testcleanup directive even though this package is supposed to expand on the existing doctest module from upstream. As a result: astropy/astropy#12150 (comment)

@saimn
Copy link
Contributor

saimn commented Sep 15, 2021

testsetup comes from astropy/sphinx-astropy@4259159 but there is no real explanation about why it was added. But this directive is doing nothing I guess, just avoiding the sphinx build to test if the sphinx extension is not present.

testcode/testsetup etc. come from the sphinx doctest extension (https://www.sphinx-doc.org/en/master/usage/extensions/doctest.html) so those doctest can be only be run with sphinx. And pytest-doctestplus is using another format to have doctest run with pytest, so 2 different things.

Pytest itself doesn't support sphinx's doctest (pytest-dev/pytest#2514) but from this ticket I see there is a pytest-sphinx plugin (https://github.com/thisch/pytest-sphinx).

Maybe we should point to that alternative in the README for people willing to use testcode ? Also this issue is kind of a duplicate of #106

@pllim
Copy link
Contributor Author

pllim commented Sep 15, 2021

So, can I use pytest-doctestplus and sphinx.ext.doctest together? All I want is to be able to run some clean-up code at the end of the RST page, while still utilizing features from this plugin. Currently, I see that sphinx-astropy does not automatically add sphinx.ext.doctest to its conf.py and I don't know if there was a specific reason for not having it there.

@pllim
Copy link
Contributor Author

pllim commented Sep 15, 2021

I am not sure if this is duplicate of #106. I have no desire to use testcode.

@saimn
Copy link
Contributor

saimn commented Sep 15, 2021

pytest-doctestplus does not know about sphinx's directives, so testclean etc. can only be used with testcode and the sphinx extension.

@pllim
Copy link
Contributor Author

pllim commented Sep 15, 2021

Now I am confused... testsetup seems to work for me at https://raw.githubusercontent.com/spacetelescope/stsynphot_refactor/master/docs/stsynphot/tutorials.rst . I didn't have to explicitly use sphinx.ext.doctest, though I also did not try to use testcleanup. I also did not use testcode.

@saimn
Copy link
Contributor

saimn commented Sep 15, 2021

Oh OK, I think this is because you are using the >>>. Since we use Python's doctest parser it will look for all the code block starting with >>> and we execute it. And then

app.add_directive('testsetup', DoctestOmitDirective, override=True)

just tells Sphinx to not render those lines. So we could do the same with testclean. But this is quite confusing because those directive are initially defined in the Sphinx extension where there are not supposed to be used with >>> ...

@pllim
Copy link
Contributor Author

pllim commented Sep 15, 2021

this is quite confusing

Confusing but works is better than nothing, right? 😅

We can try to explain in the README here... 🤷

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

Successfully merging a pull request may close this issue.

2 participants