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

DM-12061: Eliminate test warnings in test_methods.py #279

Merged
merged 5 commits into from Sep 29, 2017
Merged

Conversation

r-owen
Copy link
Contributor

@r-owen r-owen commented Sep 29, 2017

Use unittest.assertWarns if available to check that deprecated
asserts raise DeprecationWarning. If the version of Python
is too old for unittest to have assertWarngs then use a
null context manager instead (and pytest will issue warnings).

Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

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

This looks fine given that we want to minimize code changes. I'm okay with python2 silently skipping. Have you tested that this test works fine from the command line when deprecation warnings aren't enabled? I worry it needs a warnings.simplefilter('always') line somewhere.

@r-owen
Copy link
Contributor Author

r-owen commented Sep 29, 2017

Good question. The unittest documentation says of assertWarns: "This method works regardless of the warning filters in place when it is called". I double checked that by running the test as follows:

python -W ignore::DeprecationWarning tests/test_methods.py

@@ -39,7 +39,7 @@

from builtins import object
import numpy as np
import pyfits
import astropy.io
Copy link
Member

Choose a reason for hiding this comment

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

Many people do this as import astropy.io.fits as pyfits to minimize code impact but that is probably more confusing in the long term since it leaves the pyfits string in the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I considered from astropy.io import fits but felt it was too ambiguous, and in at least one case fits was already used as a variable.

Copy link
Member

Choose a reason for hiding this comment

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

Looking at other AFW code this should be plain import astropy.io.fits (we don't want to import all the other astropy IO plugins).

Use `unittest.assertWarns` if available to check that deprecated
asserts raise `DeprecationWarning`. If the version of Python
is too old for unittest to have `assertWarngs` then use a
null context manager instead (and pytest will issue warnings).
Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning up the pyfits problem.

@timj
Copy link
Member

timj commented Sep 29, 2017

In case my comment got lost when I attached it to a line; I think we need import astropy.io.fits and not import astropy.io since I don't think we want to import all the I/O plugins.

@r-owen r-owen merged commit de3749c into master Sep 29, 2017
@r-owen
Copy link
Contributor Author

r-owen commented Sep 29, 2017

Sorry, I missed that. I'll fix in on DM-10765

@r-owen
Copy link
Contributor Author

r-owen commented Sep 29, 2017

I also found and fixed another instance in test_wcsFitsTable.py on that same ticket.

@ktlim ktlim deleted the tickets/DM-12061 branch August 25, 2018 06:44
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 this pull request may close these issues.

None yet

2 participants