Skip to content

Skip doctests in two imported ufuncs#12861

Closed
lpsinger wants to merge 3 commits intoastropy:mainfrom
lpsinger:doctest-skip-flrw
Closed

Skip doctests in two imported ufuncs#12861
lpsinger wants to merge 3 commits intoastropy:mainfrom
lpsinger:doctest-skip-flrw

Conversation

@lpsinger
Copy link
Contributor

@pllim
Copy link
Member

pllim commented Feb 15, 2022

_ ERROR collecting .../astropy/cosmology/core.py _
.../astropy/cosmology/core.py:398: in __getattr__
    warnings.warn(
E   astropy.utils.exceptions.AstropyDeprecationWarning: `astropy.cosmology.core.__doctest_skip__`
has been moved (since v5.0) and should be imported as ``from astropy.cosmology import __doctest_skip__``.
In future this will raise an exception.

🤯

@nstarman , what is this about?

def __getattr__(attr):
from . import flrw
if hasattr(flrw, attr):
import warnings
from astropy.utils.exceptions import AstropyDeprecationWarning
warnings.warn(
f"`astropy.cosmology.core.{attr}` has been moved (since v5.0) and "
f"should be imported as ``from astropy.cosmology import {attr}``."
" In future this will raise an exception.",
AstropyDeprecationWarning
)
return getattr(flrw, attr)
raise AttributeError(f"module {__name__!r} has no attribute {attr!r}.")

@nstarman
Copy link
Member

nstarman commented Feb 15, 2022

@nstarman , what is this about?

A lot of FLRW-related stuff has been moved from astropy.cosmology.core to astropy.cosmology.flrw. However, everything should be imported from the top-level namespace, not the .core nor .flrw sub-modules.

In a few Astropy releases I'll get rid of the __getattr__ and importing stuff in astropy.cosmology.flrw from `astropy.cosmology.core`` will error as expected.

To avoid this raising a warning, a blank __doctest_skip__ = [] could be added to astropy.cosmology.core, then the __getattr__ won't be called.

@pllim
Copy link
Member

pllim commented Feb 15, 2022

How can adding a __doctest_skip__ here trigger this?

@nstarman
Copy link
Member

nstarman commented Feb 15, 2022

How can adding a __doctest_skip__ here trigger this?

Adding a __doctest_skip__ to astropy.cosmology.flrw means that when using hasattr(astropy.cosmology.core, "__doctest_skip__"), astropy.cosmology.core.__getattr__ will find astropy.cosmology.flrw. __doctest_skip__ and issue the warning. Before it wasn't finding anything.

@pllim
Copy link
Member

pllim commented Feb 15, 2022

Well, this complicate things...

@pllim
Copy link
Member

pllim commented Feb 15, 2022

@mhvk , @lpsinger , @nstarman , perhaps easier to move the offending imports to local import and add a note why they were moved?

@nstarman
Copy link
Member

nstarman commented Feb 15, 2022

To avoid this raising a warning, a blank __doctest_skip__ = [] could be added to astropy.cosmology.core, then the __getattr__ won't be called.

e.g. in astropy.cosmology.core

__doctest_skip__ = []  # TODO! remove this when __getattr__ is removed.

@lpsinger
Copy link
Contributor Author

To avoid this raising a warning, a blank __doctest_skip__ = [] could be added to astropy.cosmology.core, then the __getattr__ won't be called.

Ah, there's a precedent for this in

__doctest_requires__ = {} # needed until __getattr__ removed
.

@pllim
Copy link
Member

pllim commented Feb 15, 2022

I cherry-picked the commits here onto #12853 . We will see... 🤞

@lpsinger
Copy link
Contributor Author

Please also cherry-pick 3f5797e.

from .test_core import CosmologySubclassTest as CosmologyTest
from .test_core import FlatCosmologyMixinTest, ParameterTestMixin, invalid_zs, valid_zs

__doctest_skip__ = ['ellipkinc', 'hyp2f1']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test file too? I don't know how I feel about this. I feel like we are abusing __doctest_skip__.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, there is nothing about a ufunc that you can find out by introspection to determine the module it was declared in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get that a ufunc can't be introspected, but how does pytest-doctestplus pick up the test file in the first place? Shouldn't they skipped because they aren't doctested?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those two ufuncs do have doctests in their docstrings.

Copy link
Member

@nstarman nstarman Feb 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the confusion, I meant I thought pytest-doctestplus filtered out test files ab initio, but I guess that's not the case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Come again? I'm sorry, I didn't understand your question.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I presumed when pytest-doctestplus was assembling the list of docstrings it needed to check, it would skip over test files. E.g.

module/
    file.py
    tests/  # skipped
        test_file.py  # skipped, so it doesn't matter if there's a ufunc inside

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's probably a good idea. But I doubt that even pytest does that by default, does it?

@pllim
Copy link
Member

pllim commented Feb 23, 2022

@lpsinger , do we still need this in light of recent development over at scientific-python/pytest-doctestplus#175 ?

@lpsinger
Copy link
Contributor Author

@lpsinger , do we still need this in light of recent development over at astropy/pytest-doctestplus#175 ?

No.

@lpsinger
Copy link
Contributor Author

Shall we close this one, then?

@pllim
Copy link
Member

pllim commented Feb 24, 2022

Sure. Thanks!

@pllim pllim closed this Feb 24, 2022
@lpsinger lpsinger deleted the doctest-skip-flrw branch February 24, 2022 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants