From ea7357bc580a081e81a81a37ae9d6f36403d499f Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Wed, 27 Feb 2019 18:31:40 +0100 Subject: [PATCH 1/2] ci: PYTEST_ADDOPTS=-vv in general This is useful when viewing logs, especially with hanging tests. Uses non-verbose mode with a single job for full coverage. --- .travis.yml | 13 +++++++++---- azure-pipelines.yml | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 750f93f81d4..c2a6035ab1b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,8 +6,13 @@ stages: if: repo = pytest-dev/pytest AND tag IS NOT present - name: deploy if: repo = pytest-dev/pytest AND tag IS present -python: - - '3.7' +python: '3.7' +cache: false + +env: + global: + - PYTEST_ADDOPTS=-vv + install: - python -m pip install --upgrade --pre tox @@ -57,7 +62,8 @@ jobs: # - pytester's LsofFdLeakChecker # - TestArgComplete (linux only) # - numpy - - env: TOXENV=py37-lsof-numpy-xdist PYTEST_COVERAGE=1 + # Empty PYTEST_ADDOPTS to run this non-verbose. + - env: TOXENV=py37-lsof-numpy-xdist PYTEST_COVERAGE=1 PYTEST_ADDOPTS= # Specialized factors for py27. - env: TOXENV=py27-nobyte-numpy-xdist @@ -147,4 +153,3 @@ notifications: skip_join: true email: - pytest-commit@python.org -cache: false diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 712106c94e2..89ed9791f45 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -3,7 +3,7 @@ trigger: - features variables: - PYTEST_ADDOPTS: "--junitxml=build/test-results/$(tox.env).xml" + PYTEST_ADDOPTS: "--junitxml=build/test-results/$(tox.env).xml -vv" python.needs_vc: False python.exe: "python" COVERAGE_FILE: "$(Build.Repository.LocalPath)/.coverage" From 2e7d6a6202bedf9555a02d1576adf789f49ae852 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 18 Mar 2019 03:05:33 +0100 Subject: [PATCH 2/2] Fix test_assertrewrite in verbose mode Fixes https://github.com/pytest-dev/pytest/issues/4879. --- testing/test_assertrewrite.py | 69 ++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index bdfbf823c59..2d57d0494b6 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -127,7 +127,7 @@ def test_dont_rewrite_plugin(self, testdir): result = testdir.runpytest_subprocess() assert "warnings" not in "".join(result.outlines) - def test_name(self): + def test_name(self, request): def f(): assert False @@ -147,17 +147,41 @@ def f(): def f(): assert sys == 42 - assert getmsg(f, {"sys": sys}) == "assert sys == 42" + verbose = request.config.getoption("verbose") + msg = getmsg(f, {"sys": sys}) + if verbose > 0: + assert msg == ( + "assert == 42\n" + " -\n" + " +42" + ) + else: + assert msg == "assert sys == 42" def f(): - assert cls == 42 # noqa + assert cls == 42 # noqa: F821 class X(object): pass - assert getmsg(f, {"cls": X}) == "assert cls == 42" - - def test_dont_rewrite_if_hasattr_fails(self): + msg = getmsg(f, {"cls": X}).splitlines() + if verbose > 0: + if six.PY2: + assert msg == [ + "assert == 42", + " -", + " +42", + ] + else: + assert msg == [ + "assert .X'> == 42", + " -.X'>", + " +42", + ] + else: + assert msg == ["assert cls == 42"] + + def test_dont_rewrite_if_hasattr_fails(self, request): class Y(object): """ A class whos getattr fails, but not with `AttributeError` """ @@ -173,10 +197,16 @@ def __init__(self): def f(): assert cls().foo == 2 # noqa - message = getmsg(f, {"cls": Y}) - assert "assert 3 == 2" in message - assert "+ where 3 = Y.foo" in message - assert "+ where Y = cls()" in message + # XXX: looks like the "where" should also be there in verbose mode?! + message = getmsg(f, {"cls": Y}).splitlines() + if request.config.getoption("verbose") > 0: + assert message == ["assert 3 == 2", " -3", " +2"] + else: + assert message == [ + "assert 3 == 2", + " + where 3 = Y.foo", + " + where Y = cls()", + ] def test_assert_already_has_message(self): def f(): @@ -552,15 +582,16 @@ def f(): getmsg(f, must_pass=True) - def test_len(self): + def test_len(self, request): def f(): values = list(range(10)) assert len(values) == 11 - assert getmsg(f).startswith( - """assert 10 == 11 - + where 10 = len([""" - ) + msg = getmsg(f) + if request.config.getoption("verbose") > 0: + assert msg == "assert 10 == 11\n -10\n +11" + else: + assert msg == "assert 10 == 11\n + where 10 = len([0, 1, 2, 3, 4, 5, ...])" def test_custom_reprcompare(self, monkeypatch): def my_reprcompare(op, left, right): @@ -608,7 +639,7 @@ def f(): assert getmsg(f).startswith("assert '%test' == 'test'") - def test_custom_repr(self): + def test_custom_repr(self, request): def f(): class Foo(object): a = 1 @@ -619,7 +650,11 @@ def __repr__(self): f = Foo() assert 0 == f.a - assert r"where 1 = \n{ \n~ \n}.a" in util._format_lines([getmsg(f)])[0] + lines = util._format_lines([getmsg(f)]) + if request.config.getoption("verbose") > 0: + assert lines == ["assert 0 == 1\n -0\n +1"] + else: + assert lines == ["assert 0 == 1\n + where 1 = \\n{ \\n~ \\n}.a"] def test_custom_repr_non_ascii(self): def f():