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
Fix doctest for evaluate #7399
Fix doctest for evaluate #7399
Conversation
What's concerning here is that the doctest runner (obviously) isn't run on this doctest.
@@ -20,10 +20,10 @@ def evaluate(x): | |||
|
|||
>>> from sympy.abc import x | |||
>>> from sympy.core.operations import evaluate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this correct?
from sympy.core.operations doesn't work for me, from sympy.core.evaluate - does.
Indeed. Why we can't use py.test? It works:
|
It's the decoration? If you put another function in the file its doctest will be tested; but not evaluate's. |
Does py.test run the doctest in its own namespace? I know python -m doctest does not. |
I just tested it and it doesn't. py.test acts the same as def test():
"""
>>> test()
1
>>> 2
3
"""
return 1 (the second test was to make sure the test was working at all). Both
This is a pretty important feature of our doctest runner. It means that all doctests have to be completely self-contained. Executing the doctest in the module namespace is only useful if you are writing a small script or something. In most cases, and especially in our case, functions won't be run in the same module namespace as they were defined. |
Regarding this, it's got to be the decoration. But we have a ton of decorated functions. Does this mean that none of them are being doctested? |
On Sun, Apr 13, 2014 at 10:59:06AM -0700, Aaron Meurer wrote:
It seems to be the case. For example: $ cat >> sympy/core/evaluate.py <<EOF @dummy_dec $ ./bin/doctest sympy/core/evaluate.py ========================================== tests finished: 0 passed, in 0.00 seconds =========================================== Nothing was tested at all (should be a failure). |
I'm not sure if that's a fair test. The decorator should at least return a function. And anyway, |
On Sun, Apr 13, 2014 at 11:28:02AM -0700, Aaron Meurer wrote:
Why? We should have an error: In [3]: @empty In [4]: ff(2)TypeError Traceback (most recent call last) TypeError: 'NoneType' object is not callable Though, @decorated doctests seems to be working in the series |
So maybe |
The problem is that this is being raised: https://github.com/sympy/sympy/blob/master/sympy/utilities/runtests.py#L1506, and caught at https://github.com/sympy/sympy/blob/master/sympy/utilities/runtests.py#L1404. |
git blame gives 75e01c6. @thisch |
We should also look into removing that |
If I revert that commit the evaluate doctests are run. |
The issue that fixed is now #5046. I think if we can't figure this out then we should just revert that commit. It's better to have wrong line numbers than to not run doctests on decorated functions at all. |
This reverts commit 75e01c6. Conflicts: sympy/utilities/runtests.py
I've pushed a commit to this branch that reverts that. If someone wants to look into fixing this better, please do so and disregard this pull request. Otherwise, this fix should be good enough. |
@asmeurer I'll look into this in the comming days |
This seems to do the trick: --- a/sympy/utilities/runtests.py
+++ b/sympy/utilities/runtests.py
@@ -1500,7 +1500,11 @@ def _get_test(self, obj, name, module, globs, source_lines):
if lineno is None:
# handling of properties is not implemented in _find_lineno so do
# it here
- tobj = obj if not isinstance(obj, property) else obj.fget
+ if hasattr(obj, 'func_closure'):
+ tobj = obj.func_closure[0].cell_contents
+ else:
+ tobj = obj
lineno = self._find_lineno(tobj, source_lines)
assert lineno is not None |
Can you submit a pull request with that, if you have the time. We should also look into fixing that |
Although Travis passes here, so maybe there aren't any other bad doctests. |
We should definitely fix the line numbering issue, but it is more important that the tests work. Is this ready to go? |
supersedes sympy#7399 with this commit all decorated functions/methods containing doctests, where the used decorator is != ``property`` are executed now and not silently skipped.
What's concerning here is that the doctest runner (obviously) isn't run on
this doctest.