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

Resolve str AssertionErrors on ExceptionInfo objects in pytest 5 #8949

Merged
merged 6 commits into from Jul 2, 2019

Conversation

dhomeier
Copy link
Contributor

@dhomeier dhomeier commented Jul 2, 2019

Attempt to fix errors of the kind

>       assert "A Latitude angle cannot be created from a Longitude angle" in str(excinfo)
E       AssertionError: assert 'A Latitude angle cannot be created from a Longitude angle' in '<ExceptionInfo TypeError tblen=2>'
E        +  where '<ExceptionInfo TypeError tblen=2>' = str(<ExceptionInfo TypeError tblen=2>)

that started to appear with pytest 5.0.0 as discussed in #8934.
General remedy is to call str(excinfo.value) rather than str(excinfo), but there are a few cases where excinfo has no method value - see in particular patches to io and table. Apparently some hand-crafted or derived exceptions like FileNotFoundError or fits.VerifyError still return a plain string instead of an ExceptionInfo, but I could not find any hints in the pytest docs how to properly declare exception classes to better handle this.
Also excinfo.value does not contain the exception name, but since this is generally checked against immediately before, I think it can be safely omitted from the string comparison.
On the plus side, ExceptionInfo provides its own match method, simplifying some re comparisons (cf. test_html.py and test_wcsprm.py).
Tested with pytest 5.0.0 on Python 3.5 and 3.8; 4 unrelated visualisation.wcsaxes failures that turn up identically with pytest 3.10.1.

@dhomeier
Copy link
Contributor Author

dhomeier commented Jul 2, 2019

Would the changelog entry go under Bug fixes: astropy.tests?

@bsipocz
Copy link
Member

bsipocz commented Jul 2, 2019

@dhomeier - no, this is neither user facing nor has any real behaviour change, so don't need a changelog.

@bsipocz bsipocz added the 💤 merge-when-ci-passes Do not use: We have auto-merge option now. label Jul 2, 2019
@bsipocz bsipocz merged commit 661585d into astropy:master Jul 2, 2019
@bsipocz
Copy link
Member

bsipocz commented Jul 2, 2019

Thanks @dhomeier!

@dhomeier
Copy link
Contributor Author

dhomeier commented Jul 2, 2019

@bsipocz - no, definitely no user-relevant changes here, but it might be useful to document for casual developers and contributors - don't know where to best put it though.

bsipocz added a commit that referenced this pull request Jul 7, 2019
Resolve str AssertionErrors on ExceptionInfo objects in pytest 5
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.

None yet

2 participants