-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Unroll calls to any #5062 #5103
Unroll calls to any #5062 #5103
Conversation
Current roadblock - I want to recursively rewrite the assert inside the for loop, but |
Codecov Report
@@ Coverage Diff @@
## features #5103 +/- ##
============================================
+ Coverage 91.48% 93.27% +1.78%
============================================
Files 115 115
Lines 26179 26194 +15
Branches 2582 2582
============================================
+ Hits 23951 24433 +482
+ Misses 1904 1445 -459
+ Partials 324 316 -8
Continue to review full report at Codecov.
|
Ok it's at a point where it shows a better report but not quite detailed enough, would like a proposition on where to take it from here test_example.py F [100%]
=================================== FAILURES ===================================
_________________________________ test_rolled __________________________________
def test_rolled():
> assert all(x == 1 for x in range(10))
E assert 0 == 1
test_example.py:2: AssertionError The rewritten ast is exactly as expected, just as if it was a for loop: =========================== Rewritten AST as Python ============================
import builtins as @py_builtins
import _pytest.assertion.rewrite as @pytest_ar
def test_rolled():
for x in range(10):
import builtins as @py_builtins
import _pytest.assertion.rewrite as @pytest_ar
@py_assert2 = 1
@py_assert1 = x == @py_assert2
if not @py_assert1:
@py_format4 = @pytest_ar._call_reprcompare(('==',), (@py_assert1,), ('%(py0)s == %(py3)s',), (x, @py_assert2)) % {'py0': @pytest_ar._saferepr(x) if 'x' in @py_builtins.locals() or @pytest_ar._should_repr_global_name(x) else 'x', 'py3': @pytest_ar._saferepr(@py_assert2)}
@py_format6 = ('' + 'assert %(py5)s') % {'py5': @py_format4}
raise AssertionError(@pytest_ar._format_explanation(@py_format6))
@py_assert1 = @py_assert2 = None
if 1 is None:
from _pytest.warning_types import PytestWarning
from warnings import warn_explicit
warn_explicit(PytestWarning('asserting the value None, please use "assert is None"'), category=None, filename='/Users/me/Forks/pytest/test_example.py', lineno=2)
if not 1:
@py_format0 = ('' + 'assert ') % {}
raise AssertionError(@pytest_ar._format_explanation(@py_format0))
=========================== short test summary info ============================
FAILED test_example.py::test_rolled
=========================== 1 failed in 0.10 seconds =========================== |
I'm not going to be able to continue this until next week - @danielx123 if you want to fork this until then you're more than welcome! |
src/_pytest/assertion/rewrite.py
Outdated
@@ -987,6 +989,27 @@ def visit_Call_35(self, call): | |||
outer_expl = "%s\n{%s = %s\n}" % (res_expl, res_expl, expl) | |||
return res, outer_expl | |||
|
|||
def visit_all(self, call): | |||
"""Special rewrite for the builtin all function, see #5602""" |
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.
@Tadaboody I can work on this during the weekend. How do you want to work on this together? |
Alright I think this is pretty stable and does what it's supposed to. @nicoddemus I'll be waiting to start a review process |
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.
Hi @Tadaboody,
Great job!
Here's what we get on master
with your samples:
============================= FAILURES ==============================
__________________________ test_generator ___________________________
def test_generator():
odd_list = list(range(1,9,2))
> assert all(check_even(num) for num in odd_list)
E assert False
E + where False = all(<generator object test_generator.<locals>.<genexpr> at 0x000001D7A54FA678>)
.tmp\test-foo.py:8: AssertionError
______________________ test_list_comprehension ______________________
def test_list_comprehension():
odd_list = list(range(1,9,2))
> assert all([check_even(num) for num in odd_list])
E assert False
E + where False = all([False, False, False, False])
.tmp\test-foo.py:13: AssertionError
___________________________ test_for_loop ___________________________
def test_for_loop():
odd_list = list(range(1,9,2))
for num in odd_list:
> assert check_even(num)
E assert False
E + where False = check_even(1)
.tmp\test-foo.py:19: AssertionError
===================== 3 failed in 0.11 seconds ======================
And with your branch:
============================= FAILURES ==============================
__________________________ test_generator ___________________________
def test_generator():
odd_list = list(range(1,9,2))
> assert all(check_even(num) for num in odd_list)
E assert False
E + where False = check_even(1)
.tmp\test-foo.py:8: AssertionError
______________________ test_list_comprehension ______________________
def test_list_comprehension():
odd_list = list(range(1,9,2))
> assert all([check_even(num) for num in odd_list])
E assert False
E + where False = check_even(1)
.tmp\test-foo.py:13: AssertionError
___________________________ test_for_loop ___________________________
def test_for_loop():
odd_list = list(range(1,9,2))
for num in odd_list:
> assert check_even(num)
E assert False
E + where False = check_even(1)
.tmp\test-foo.py:19: AssertionError
===================== 3 failed in 0.10 seconds ======================
Do you mind rebasing on |
…ting The code ``` x = 0 assert x == 1 ``` will give the failure message 0 == 1, so it shouldn't be different as part of an unroll
rebased |
Merging as the failure is unrelated: #5317 |
Thanks @Tadaboody! |
It turns out that it is not really it seems.. ;) |
😮 |
Closes #5062
changelog
folder, with a name like<ISSUE NUMBER>.<TYPE>.rst
. See changelog/README.rst for details.master
branch for bug fixes, documentation updates and trivial changes.features
branch for new features and removals/deprecations.