@@ -127,7 +127,7 @@ def test_dont_rewrite_plugin(self, testdir):
127
127
result = testdir .runpytest_subprocess ()
128
128
assert "warnings" not in "" .join (result .outlines )
129
129
130
- def test_name (self ):
130
+ def test_name (self , request ):
131
131
def f ():
132
132
assert False
133
133
@@ -147,17 +147,41 @@ def f():
147
147
def f ():
148
148
assert sys == 42
149
149
150
- assert getmsg (f , {"sys" : sys }) == "assert sys == 42"
150
+ verbose = request .config .getoption ("verbose" )
151
+ msg = getmsg (f , {"sys" : sys })
152
+ if verbose > 0 :
153
+ assert msg == (
154
+ "assert <module 'sys' (built-in)> == 42\n "
155
+ " -<module 'sys' (built-in)>\n "
156
+ " +42"
157
+ )
158
+ else :
159
+ assert msg == "assert sys == 42"
151
160
152
161
def f ():
153
- assert cls == 42 # noqa
162
+ assert cls == 42 # noqa: F821
154
163
155
164
class X (object ):
156
165
pass
157
166
158
- assert getmsg (f , {"cls" : X }) == "assert cls == 42"
159
-
160
- def test_dont_rewrite_if_hasattr_fails (self ):
167
+ msg = getmsg (f , {"cls" : X }).splitlines ()
168
+ if verbose > 0 :
169
+ if six .PY2 :
170
+ assert msg == [
171
+ "assert <class 'test_assertrewrite.X'> == 42" ,
172
+ " -<class 'test_assertrewrite.X'>" ,
173
+ " +42" ,
174
+ ]
175
+ else :
176
+ assert msg == [
177
+ "assert <class 'test_...e.<locals>.X'> == 42" ,
178
+ " -<class 'test_assertrewrite.TestAssertionRewrite.test_name.<locals>.X'>" ,
179
+ " +42" ,
180
+ ]
181
+ else :
182
+ assert msg == ["assert cls == 42" ]
183
+
184
+ def test_dont_rewrite_if_hasattr_fails (self , request ):
161
185
class Y (object ):
162
186
""" A class whos getattr fails, but not with `AttributeError` """
163
187
@@ -173,10 +197,16 @@ def __init__(self):
173
197
def f ():
174
198
assert cls ().foo == 2 # noqa
175
199
176
- message = getmsg (f , {"cls" : Y })
177
- assert "assert 3 == 2" in message
178
- assert "+ where 3 = Y.foo" in message
179
- assert "+ where Y = cls()" in message
200
+ # XXX: looks like the "where" should also be there in verbose mode?!
201
+ message = getmsg (f , {"cls" : Y }).splitlines ()
202
+ if request .config .getoption ("verbose" ) > 0 :
203
+ assert message == ["assert 3 == 2" , " -3" , " +2" ]
204
+ else :
205
+ assert message == [
206
+ "assert 3 == 2" ,
207
+ " + where 3 = Y.foo" ,
208
+ " + where Y = cls()" ,
209
+ ]
180
210
181
211
def test_assert_already_has_message (self ):
182
212
def f ():
@@ -552,15 +582,16 @@ def f():
552
582
553
583
getmsg (f , must_pass = True )
554
584
555
- def test_len (self ):
585
+ def test_len (self , request ):
556
586
def f ():
557
587
values = list (range (10 ))
558
588
assert len (values ) == 11
559
589
560
- assert getmsg (f ).startswith (
561
- """assert 10 == 11
562
- + where 10 = len(["""
563
- )
590
+ msg = getmsg (f )
591
+ if request .config .getoption ("verbose" ) > 0 :
592
+ assert msg == "assert 10 == 11\n -10\n +11"
593
+ else :
594
+ assert msg == "assert 10 == 11\n + where 10 = len([0, 1, 2, 3, 4, 5, ...])"
564
595
565
596
def test_custom_reprcompare (self , monkeypatch ):
566
597
def my_reprcompare (op , left , right ):
@@ -608,7 +639,7 @@ def f():
608
639
609
640
assert getmsg (f ).startswith ("assert '%test' == 'test'" )
610
641
611
- def test_custom_repr (self ):
642
+ def test_custom_repr (self , request ):
612
643
def f ():
613
644
class Foo (object ):
614
645
a = 1
@@ -619,7 +650,11 @@ def __repr__(self):
619
650
f = Foo ()
620
651
assert 0 == f .a
621
652
622
- assert r"where 1 = \n{ \n~ \n}.a" in util ._format_lines ([getmsg (f )])[0 ]
653
+ lines = util ._format_lines ([getmsg (f )])
654
+ if request .config .getoption ("verbose" ) > 0 :
655
+ assert lines == ["assert 0 == 1\n -0\n +1" ]
656
+ else :
657
+ assert lines == ["assert 0 == 1\n + where 1 = \\ n{ \\ n~ \\ n}.a" ]
623
658
624
659
def test_custom_repr_non_ascii (self ):
625
660
def f ():
0 commit comments