File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 38
38
39
39
* Renamed the pytest ``pdb `` module (plugin) into ``debugging ``.
40
40
41
+ * Improve of the test output for logical expression with brackets.
42
+ Fixes(`#925 `_). Thanks `@DRMacIver `_ for reporting. Thanks to `@RedBeardCode `_
43
+ for PR.
44
+
41
45
*
42
46
43
47
* ImportErrors in plugins now are a fatal error instead of issuing a
51
55
.. _#1626 : https://github.com/pytest-dev/pytest/pull/1626
52
56
.. _#1503 : https://github.com/pytest-dev/pytest/issues/1503
53
57
.. _#1479 : https://github.com/pytest-dev/pytest/issues/1479
58
+ .. _#925 : https://github.com/pytest-dev/pytest/issues/925
54
59
55
60
.. _@graingert : https://github.com/graingert
56
61
.. _@taschini : https://github.com/taschini
59
64
.. _@Vogtinator : https://github.com/Vogtinator
60
65
.. _@bagerard : https://github.com/bagerard
61
66
.. _@davehunt : https://github.com/davehunt
67
+ .. _@DRMacIver : https://github.com/DRMacIver
62
68
63
69
64
70
2.9.2
Original file line number Diff line number Diff line change 1
1
"""Rewrite assertion AST to produce nice error messages"""
2
2
3
3
import ast
4
+ import _ast
4
5
import errno
5
6
import itertools
6
7
import imp
@@ -855,6 +856,8 @@ def visit_Attribute(self, attr):
855
856
def visit_Compare (self , comp ):
856
857
self .push_format_context ()
857
858
left_res , left_expl = self .visit (comp .left )
859
+ if isinstance (comp .left , (_ast .Compare , _ast .BoolOp )):
860
+ left_expl = "({0})" .format (left_expl )
858
861
res_variables = [self .variable () for i in range (len (comp .ops ))]
859
862
load_names = [ast .Name (v , ast .Load ()) for v in res_variables ]
860
863
store_names = [ast .Name (v , ast .Store ()) for v in res_variables ]
@@ -864,6 +867,8 @@ def visit_Compare(self, comp):
864
867
results = [left_res ]
865
868
for i , op , next_operand in it :
866
869
next_res , next_expl = self .visit (next_operand )
870
+ if isinstance (next_operand , (_ast .Compare , _ast .BoolOp )):
871
+ next_expl = "({0})" .format (next_expl )
867
872
results .append (next_res )
868
873
sym = binop_map [op .__class__ ]
869
874
syms .append (ast .Str (sym ))
Original file line number Diff line number Diff line change @@ -720,3 +720,30 @@ def test_long_repr():
720
720
""" )
721
721
result = testdir .runpytest ()
722
722
assert 'unbalanced braces' not in result .stdout .str ()
723
+
724
+
725
+ class TestIssue925 ():
726
+ def test_simple_case (self , testdir ):
727
+ testdir .makepyfile ("""
728
+ def test_ternary_display():
729
+ assert (False == False) == False
730
+ """ )
731
+ result = testdir .runpytest ()
732
+ result .stdout .fnmatch_lines ('*E*assert (False == False) == False' )
733
+
734
+ def test_long_case (self , testdir ):
735
+ testdir .makepyfile ("""
736
+ def test_ternary_display():
737
+ assert False == (False == True) == True
738
+ """ )
739
+ result = testdir .runpytest ()
740
+ result .stdout .fnmatch_lines ('*E*assert (False == True) == True' )
741
+
742
+ def test_many_brackets (self , testdir ):
743
+ testdir .makepyfile ("""
744
+ def test_ternary_display():
745
+ assert True == ((False == True) == True)
746
+ """ )
747
+ result = testdir .runpytest ()
748
+ result .stdout .fnmatch_lines ('*E*assert True == ((False == True) == True)' )
749
+
You can’t perform that action at this time.
0 commit comments