-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
TST: DocTestFailure 'MaskedArray' object has no attribute 'unit' #14005
Comments
So I can reproduce this locally now using python 3.10 in a brand new environment. I have tested every (merge) commit back to 0c37a71, the merge commit for #13484 and found this error persists that far back. Since #13484 occurred before any of the |
I carefully reviewed the two CI runs related to this failure:
Since #14005 (comment) indicated that the error is not related to the merge, I went through the pip-freeze in both cases. The only difference I could see is the failing CI used Thus I believe that |
It looks like the changes causing this issue originate in agronholm/exceptiongroup#42. Should we just pin |
It looks as though the exception type is the same, but the message has changed. Given that exception type and message are the only things that doctest cares about, one could also ignore the exception detail, especially if this is Python 3.12 behavior being backported. https://docs.python.org/3/library/doctest.html#what-about-exceptions I.e. >>> np_mq.unit # doctest: +IGNORE_EXCEPTION_DETAIL Especially if this is the only test affected. From reading the changes in It might be worth filing an issue indicating that this |
Actually something more insidious and confusing is happening. If I do the following in Python 3.11: >>> class Foo:
... def __init__(self):
... pass
...
... def _bar(self):
... return 42
...
>>> foo = Foo()
>>> foo.bar
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Foo' object has no attribute 'bar'. Did you mean: '_bar'? I get the suggestion. Fun! So this is already baked into Python 3.11. But when I then make this into a module # foo.py
class Foo:
def __init__(self):
pass
def _bar(self):
return 42
def func():
"""
This docstring tests Foo
Example
-------
>>> foo = Foo()
>>> foo.bar
Traceback (most recent call last):
...
AttributeError: 'Foo' object has no attribute 'bar'. Did you mean: '_bar'?
"""
pass and run pytest and w/doctest on it (under Python 3.11), it fails:
So pytest w/doctest actually gives me the wrong exception message under Python 3.11. This is a bug. Meanwhile, if I do the same exercise above under Python 3.10: >>> class Foo:
... def __init__(self):
... pass
...
... def _bar(self):
... return 42
...
>>> foo = Foo()
>>> foo.bar
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Foo' object has no attribute 'bar'. Did you mean: '_bar'? I also get the suggestion. But when I run pytest w/doctest, again under Python 3.10:
everything passes. So TL;DR, it seems that Python 3.11 with pytest is the thing that is broken right now. It must strip away suggestions or something. |
Btw, these For 3.12 it is apparently supposed to be in the traceback itself, not computed on-the-fly, but this is not yet the case in 3.11.0. The example below shows this: >>> class Foo:
... def __init__(self):
... pass
...
... def _bar(self):
... return 42
...
>>> foo = Foo()
>>> foo.bar
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'Foo' object has no attribute 'bar'. Did you mean: '_bar'?
>>> try:
... foo.bar
... except AttributeError as e:
... print(e)
...
'Foo' object has no attribute 'bar' |
I don't know yet why stuff breaks with pytest, if exceptiongroup is to blame I'm happy to look into that more. Just chiming in to say that it's very much intentional on the CPython side that the suggestions are only computed when printing the traceback. computing the suggestion is relatively costly (it does |
right, I think I see. so the problem is that CPython has two different exception printing mechanisms, one is the
so now Sorry for the wall of text. All this to say that a pragmatic solution would be to ignore the tail end of the error message in the doctest and wait for 3.12 |
Exactly. Thanks for distilling that. 🙌 And because there are lots of docstring examples in the wild that are tested daily via CI by Agree the short-term pragmatic answer is to use |
or you could do this kind of thing: >>> foo.bar # doctest: +ELLIPSIS
Traceback (most recent call last):
...
AttributeError: 'Foo' object has no attribute 'bar'... note the |
@jdavies-st and @cfbolz thanks for figuring out the root cause of the issue. The final solution of just adding an |
Thanks all for finding and fixing this issue! I think it can also be closed -- if we want something more general probably good to open another issue. |
Accepted solution LGTM. Belated thanks to everyone involved to help resolve this problem so quickly! |
Hold your horses, @astrofrog and @WilliamJamieson ! We need to fix this before merging more
black
stuff. I think one of them broke a doctest. The PRs might be fine individually but maybe didn't play well together. cc @mhvkExample log: https://github.com/astropy/astropy/actions/runs/3465731975/jobs/5788828409
The text was updated successfully, but these errors were encountered: