Skip to content

Commit 6eff306

Browse files
authored
Merge pull request #4851 from blueyed/addopts-vv
ci: PYTEST_ADDOPTS=-vv
2 parents 58a14b6 + 2e7d6a6 commit 6eff306

File tree

3 files changed

+62
-22
lines changed

3 files changed

+62
-22
lines changed

.travis.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@ stages:
66
if: repo = pytest-dev/pytest AND tag IS NOT present
77
- name: deploy
88
if: repo = pytest-dev/pytest AND tag IS present
9-
python:
10-
- '3.7'
9+
python: '3.7'
10+
cache: false
11+
12+
env:
13+
global:
14+
- PYTEST_ADDOPTS=-vv
15+
1116
install:
1217
- python -m pip install --upgrade --pre tox
1318

@@ -57,7 +62,8 @@ jobs:
5762
# - pytester's LsofFdLeakChecker
5863
# - TestArgComplete (linux only)
5964
# - numpy
60-
- env: TOXENV=py37-lsof-numpy-xdist PYTEST_COVERAGE=1
65+
# Empty PYTEST_ADDOPTS to run this non-verbose.
66+
- env: TOXENV=py37-lsof-numpy-xdist PYTEST_COVERAGE=1 PYTEST_ADDOPTS=
6167

6268
# Specialized factors for py27.
6369
- env: TOXENV=py27-nobyte-numpy-xdist
@@ -147,4 +153,3 @@ notifications:
147153
skip_join: true
148154
email:
149155
150-
cache: false

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ trigger:
33
- features
44

55
variables:
6-
PYTEST_ADDOPTS: "--junitxml=build/test-results/$(tox.env).xml"
6+
PYTEST_ADDOPTS: "--junitxml=build/test-results/$(tox.env).xml -vv"
77
python.needs_vc: False
88
python.exe: "python"
99
COVERAGE_FILE: "$(Build.Repository.LocalPath)/.coverage"

testing/test_assertrewrite.py

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def test_dont_rewrite_plugin(self, testdir):
127127
result = testdir.runpytest_subprocess()
128128
assert "warnings" not in "".join(result.outlines)
129129

130-
def test_name(self):
130+
def test_name(self, request):
131131
def f():
132132
assert False
133133

@@ -147,17 +147,41 @@ def f():
147147
def f():
148148
assert sys == 42
149149

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"
151160

152161
def f():
153-
assert cls == 42 # noqa
162+
assert cls == 42 # noqa: F821
154163

155164
class X(object):
156165
pass
157166

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):
161185
class Y(object):
162186
""" A class whos getattr fails, but not with `AttributeError` """
163187

@@ -173,10 +197,16 @@ def __init__(self):
173197
def f():
174198
assert cls().foo == 2 # noqa
175199

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+
]
180210

181211
def test_assert_already_has_message(self):
182212
def f():
@@ -552,15 +582,16 @@ def f():
552582

553583
getmsg(f, must_pass=True)
554584

555-
def test_len(self):
585+
def test_len(self, request):
556586
def f():
557587
values = list(range(10))
558588
assert len(values) == 11
559589

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, ...])"
564595

565596
def test_custom_reprcompare(self, monkeypatch):
566597
def my_reprcompare(op, left, right):
@@ -608,7 +639,7 @@ def f():
608639

609640
assert getmsg(f).startswith("assert '%test' == 'test'")
610641

611-
def test_custom_repr(self):
642+
def test_custom_repr(self, request):
612643
def f():
613644
class Foo(object):
614645
a = 1
@@ -619,7 +650,11 @@ def __repr__(self):
619650
f = Foo()
620651
assert 0 == f.a
621652

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"]
623658

624659
def test_custom_repr_non_ascii(self):
625660
def f():

0 commit comments

Comments
 (0)