Skip to content

EXP: Run test suite with dev pytest-doctestplus#12853

Closed
pllim wants to merge 2 commits intoastropy:mainfrom
pllim:ufunc-ifunk
Closed

EXP: Run test suite with dev pytest-doctestplus#12853
pllim wants to merge 2 commits intoastropy:mainfrom
pllim:ufunc-ifunk

Conversation

@pllim
Copy link
Member

@pllim pllim commented Feb 14, 2022

Description

This pull request is to see if scientific-python/pytest-doctestplus#174 broke anything here.

Checklist for package maintainer(s)

This checklist is meant to remind the package maintainer(s) who will review this pull request of some common things to look for. This list is not exhaustive.

  • Do the proposed changes actually accomplish desired goals?
  • Do the proposed changes follow the Astropy coding guidelines?
  • Are tests added/updated as required? If so, do they follow the Astropy testing guidelines?
  • Are docs added/updated as required? If so, do they follow the Astropy documentation guidelines?
  • Is rebase and/or squash necessary? If so, please provide the author with appropriate instructions. Also see "When to rebase and squash commits".
  • Did the CI pass? If no, are the failures related? If you need to run daily and weekly cron jobs as part of the PR, please apply the Extra CI label.
  • Is a change log needed? If yes, did the change log check pass? If no, add the no-changelog-entry-needed label. If this is a manual backport, use the skip-changelog-checks label unless special changelog handling is necessary.
  • Is this a big PR that makes a "What's new?" entry worthwhile and if so, is (1) a "what's new" entry included in this PR and (2) the "whatsnew-needed" label applied?
  • Is a milestone set? Milestone must be set but astropy-bot check might be missing; do not let the green checkmark fool you.
  • At the time of adding the milestone, if the milestone set requires a backport to release branch(es), apply the appropriate backport-X.Y.x label(s) before merge.

@github-actions
Copy link
Contributor

👋 Thank you for your draft pull request! Do you know that you can use [ci skip] or [skip ci] in your commit messages to skip running continuous integration tests until you are ready?

@lpsinger
Copy link
Contributor

Why not permanently add this to devdeps?

@pllim
Copy link
Member Author

pllim commented Feb 14, 2022

I guess we could... Will add it to infrastructure agenda.

@pllim
Copy link
Member Author

pllim commented Feb 14, 2022

Failure looks related. But what do we do, @lpsinger or @mhvk ?

______________________________ [doctest] arctan2 _______________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> np.arctan2([0., 0., np.inf], [+0., -0., np.inf])
Expected:
    array([ 0.        ,  3.14159265,  0.78539816])
Got:
    array([0.        , 3.14159265, 0.78539816])

.../astropy/units/quantity_helper/helpers.py:None: DocTestFailure

@lpsinger
Copy link
Contributor

lpsinger commented Feb 15, 2022

The failing doctest is in Numpy itself, here. This is proof that we are now discovering tests in ufuncs! 🤣

The question is, why is pytest discovering tests in Numpy?

@lpsinger
Copy link
Contributor

#12858 should fix this.

@pllim
Copy link
Member Author

pllim commented Feb 15, 2022

What about these new errors?

_______________________________ [doctest] hyp2f1 _______________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> np.arctan(z) / z
Expected:
    0.9272952180016123
Got:
    0.9272952180016122

/home/runner/work/astropy/astropy/astropy/cosmology/flrw.py:None: DocTestFailure
_______________________________ [doctest] hyp2f1 _______________________________
EXAMPLE LOCATION UNKNOWN, not showing all tests of that example
??? >>> np.arctan(z) / z
Expected:
    0.9272952180016123
Got:
    0.9272952180016122

/home/runner/work/astropy/astropy/astropy/cosmology/tests/test_flrw.py:None: DocTestFailure

@lpsinger
Copy link
Contributor

Hmm, there are several Astropy modules that have from scipy.special import ... in them.

@lpsinger
Copy link
Contributor

But astropy.cosmology.flrw is the only module in which the import is at global rather than function scope.

@pllim
Copy link
Member Author

pllim commented Feb 15, 2022

So having this new pytest-doctestplus plugin means we have to be real careful of imports? I think this should be documented in the dev docs then. When to import globally and when not to.

@mhvk
Copy link
Contributor

mhvk commented Feb 15, 2022

@lpsinger - the fact that most imports are local is almost certainly because scipy is not (yet) a required dependency for most of astropy. But for cosmology it is, hence the imports on top.

I'm starting to wonder a bit if the gain is worth the pain... Maybe after all there should be a switch on doctestplus to turn off ufunc doc tests? Of course, really the ufuncs should expose the module they are defined in!

@lpsinger
Copy link
Contributor

@saimn
Copy link
Contributor

saimn commented Feb 16, 2022

I'm starting to wonder a bit if the gain is worth the pain... Maybe after all there should be a switch on doctestplus to turn off ufunc doc tests? Of course, really the ufuncs should expose the module they are defined in!

Agreed. And instead of having to have __doctest_skip__ in every module where some ufunc is imported, we should probably do the opposite, i.e. define a __doctest_ufunc__ that would allow to activate doctesting ufuncs on a case by case basis ?

@lpsinger
Copy link
Contributor

I'm starting to wonder a bit if the gain is worth the pain... Maybe after all there should be a switch on doctestplus to turn off ufunc doc tests? Of course, really the ufuncs should expose the module they are defined in!

Agreed. And instead of having to have __doctest_skip__ in every module where some ufunc is imported, we should probably do the opposite, i.e. define a __doctest_ufunc__ that would allow to activate doctesting ufuncs on a case by case basis ?

Or we could make the ufunc doctest discovery an opt-in using a --doctest-ufunc option to pytest-doctestplus, which was in my original draft.

@saimn
Copy link
Contributor

saimn commented Feb 17, 2022

Yes, so at least now we found the drawback of activating it by default ;). The problem with the global switch is that we would face the same issue if we want to use it in Astropy. So, since ufunc can be doctested only if imported in another module (I think ?), maybe a module level directive (e.g. __doctest_ufunc__) is a better approach ?

@pllim
Copy link
Member Author

pllim commented Feb 18, 2022

So... what is the path forward here?

@nstarman
Copy link
Member

nstarman commented Feb 18, 2022

I think we are all agreed that doctesting ufuncs is a good idea. The question is whether we want to opt in or opt out of testing specific files.

__doctest_skip__ __doctest_ufunc__
ufunc testing on globally need to add skips to all offending files doesn't do anything
ufunc testing off globally doesn't do anything need to add for each desired function

I actually think the optimal solution is a --doctest-ufunc flag that defaults to False. __doctest_ufunc__ turns on testing on a case-by-case basis, regardless of whether --doctest-ufunc is True or False, and __doctest_skip__ does the same, but for turning testing off on a case-by-case basis. This implementation nicely gets any scenario in the above table.
Unfortunately, this solution is the most work.

@lpsinger
Copy link
Contributor

I agree; I like --doctest-ufunc. My original application is in a coordinated package with lots of ufuncs, so I'd rather not list them all out explicitly in __doctest_ufunc__. I'll add the --doctest-ufunc option back to this PR.

@pllim
Copy link
Member Author

pllim commented Feb 24, 2022

Rebased and dropped the cherry-picks. 🤞

@nstarman
Copy link
Member

21/21 = 💯 🎉

@pllim
Copy link
Member Author

pllim commented Apr 7, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants