Skip to content

Conversation

@saimn
Copy link
Contributor

@saimn saimn commented Dec 11, 2020

For astropy/astropy#11137
Basically copy/pasted from IGNORE_WARNINGS

@saimn saimn requested review from astrofrog and pllim December 11, 2020 02:59
Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Not clear from the doc if it can be used together with IGNORE_WARNINGS or is mutually exclusive with it.

Also would be curious to know how it interacts with filter_warnings set in setup.cfg, or inside a warnings.catch_warnings context manager.

@pllim pllim added this to the 0.9.0 milestone Dec 11, 2020
@saimn
Copy link
Contributor Author

saimn commented Dec 11, 2020

Not clear from the doc if it can be used together with IGNORE_WARNINGS or is mutually exclusive with it.

It doesn't make sense to use both. But if you do I guess the inner call will win.

Also would be curious to know how it interacts with filter_warnings set in setup.cfg,

The goal is actually to override the default settings in setup.cfg (which for astropy turns warnings into exceptions)

or inside a warnings.catch_warnings context manager.

It wraps the code, so the warnings that would be catch manually with catch_warnings would not be seen by the doctest flag.

@pllim
Copy link
Contributor

pllim commented Dec 11, 2020

Re: #136 (comment) -- Can we document this in README? 😸

.. code-block:: python
>>> import numpy as np
>>> np.mean([]) # doctest: +SHOW_WARNINGS
Copy link
Contributor

Choose a reason for hiding this comment

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

One more question: If the expected warning does not show, will doctest fail or ignore?

Is this the doctest equivalent of pytest.warns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One more question: If the expected warning does not show, will doctest fail or ignore?

Yep. I added more tests.

Is this the doctest equivalent of pytest.warns?

Yes, it can be seen as such.

Copy link
Contributor

@pllim pllim left a comment

Choose a reason for hiding this comment

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

Thanks! LGTM. I'll leave it open in case @astrofrog wants to review too.

Copy link
Contributor

@astrofrog astrofrog left a comment

Choose a reason for hiding this comment

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

Looks good to me, thanks!

@astrofrog astrofrog merged commit f0cbc1b into scientific-python:master Dec 13, 2020
@saimn saimn deleted the show-warnings branch December 14, 2020 13:16
@saimn
Copy link
Contributor Author

saimn commented Dec 14, 2020

Thanks. Will need a release ;)

eerovaher added a commit to eerovaher/pytest-astropy that referenced this pull request Jun 2, 2021
The previous minimum required version was 0.2.0. However, Astropy
documentation testing makes use of the '+SHOW_WARNINGS' option, which
was introduced by scientific-python/pytest-doctestplus#136 and therefore the
actual minimum required pytest-doctestplus version is 0.9.0.
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