Skip to content

pytest warnings summary displayed by default #1704

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

Merged
merged 11 commits into from
Jul 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Alexei Kozlenok
Anatoly Bubenkoff
Andreas Zeidler
Andy Freeland
Andrzej Ostrowski
Anthon van der Neut
Armin Rigo
Aron Curzon
Expand Down
22 changes: 22 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,41 @@
Thanks `@Vogtinator`_ for reporting. Thanks to `@RedBeardCode`_ and
`@tomviner`_ for PR.

* Rename ``getfuncargvalue`` to ``getfixturevalue``. ``getfuncargvalue`` is
deprecated but still present. Thanks to `@RedBeardCode`_ and `@tomviner`_
for PR (`#1626`_).

* Always include full assertion explanation. The previous behaviour was hiding
sub-expressions that happened to be False, assuming this was redundant information.
Thanks `@bagerard`_ for reporting (`#1503`_). Thanks to `@davehunt`_ and
`@tomviner`_ for PR.

* Now pytest warnings summary is shown up by default. Added a new flag
``--disable-pytest-warnings`` to explicitly disable the warnings summary.
This change resolves the (`#1668`_).

* Renamed the pytest ``pdb`` module (plugin) into ``debugging``.

*

*

.. _#1580: https://github.com/pytest-dev/pytest/pull/1580
.. _#1605: https://github.com/pytest-dev/pytest/issues/1605
.. _#1597: https://github.com/pytest-dev/pytest/pull/1597
.. _#460: https://github.com/pytest-dev/pytest/pull/460
.. _#1553: https://github.com/pytest-dev/pytest/issues/1553
.. _#1626: https://github.com/pytest-dev/pytest/pull/1626
.. _#1503: https://github.com/pytest-dev/pytest/issues/1503
.. _#1668: https://github.com/pytest-dev/pytest/issues/1668

.. _@graingert: https://github.com/graingert
.. _@taschini: https://github.com/taschini
.. _@nikratio: https://github.com/nikratio
.. _@RedBeardCode: https://github.com/RedBeardCode
.. _@Vogtinator: https://github.com/Vogtinator
.. _@bagerard: https://github.com/bagerard
.. _@davehunt: https://github.com/davehunt


2.9.2
Expand Down
33 changes: 0 additions & 33 deletions _pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,44 +38,11 @@ def format_explanation(explanation):
displaying diffs.
"""
explanation = ecu(explanation)
explanation = _collapse_false(explanation)
lines = _split_explanation(explanation)
result = _format_lines(lines)
return u('\n').join(result)


def _collapse_false(explanation):
"""Collapse expansions of False

So this strips out any "assert False\n{where False = ...\n}"
blocks.
"""
where = 0
while True:
start = where = explanation.find("False\n{False = ", where)
if where == -1:
break
level = 0
prev_c = explanation[start]
for i, c in enumerate(explanation[start:]):
if prev_c + c == "\n{":
level += 1
elif prev_c + c == "\n}":
level -= 1
if not level:
break
prev_c = c
else:
raise AssertionError("unbalanced braces: %r" % (explanation,))
end = start + i
where = end
if explanation[end - 1] == '\n':
explanation = (explanation[:start] + explanation[start+15:end-1] +
explanation[end+1:])
where -= 17
return explanation


def _split_explanation(explanation):
"""Return a list of individual lines in the explanation

Expand Down
2 changes: 1 addition & 1 deletion _pytest/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class UsageError(Exception):
_preinit = []

default_plugins = (
"mark main terminal runner python pdb unittest capture skipping "
"mark main terminal runner python debugging unittest capture skipping "
"tmpdir monkeypatch recwarn pastebin helpconfig nose assertion genscript "
"junitxml resultlog doctest cacheprovider").split()

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion _pytest/doctest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, name, parent, runner=None, dtest=None):
def setup(self):
if self.dtest is not None:
self.fixture_request = _setup_fixtures(self)
globs = dict(getfixture=self.fixture_request.getfuncargvalue)
globs = dict(getfixture=self.fixture_request.getfixturevalue)
self.dtest.globs.update(globs)

def runtest(self):
Expand Down
27 changes: 17 additions & 10 deletions _pytest/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import re
import types
import sys
import warnings

import py
import pytest
Expand Down Expand Up @@ -1469,7 +1470,7 @@ def _getnextfixturedef(self, argname):
fixturedefs = self._arg2fixturedefs.get(argname, None)
if fixturedefs is None:
# we arrive here because of a a dynamic call to
# getfuncargvalue(argname) usage which was naturally
# getfixturevalue(argname) usage which was naturally
# not known at parsing/collection time
fixturedefs = self._fixturemanager.getfixturedefs(
argname, self._pyfuncitem.parent.nodeid)
Expand Down Expand Up @@ -1564,7 +1565,7 @@ def _fillfixtures(self):
fixturenames = getattr(item, "fixturenames", self.fixturenames)
for argname in fixturenames:
if argname not in item.funcargs:
item.funcargs[argname] = self.getfuncargvalue(argname)
item.funcargs[argname] = self.getfixturevalue(argname)

def cached_setup(self, setup, teardown=None, scope="module", extrakey=None):
""" (deprecated) Return a testing resource managed by ``setup`` &
Expand Down Expand Up @@ -1598,17 +1599,23 @@ def finalizer():
self._addfinalizer(finalizer, scope=scope)
return val

def getfuncargvalue(self, argname):
""" Dynamically retrieve a named fixture function argument.
def getfixturevalue(self, argname):
""" Dynamically run a named fixture function.

As of pytest-2.3, it is easier and usually better to access other
fixture values by stating it as an input argument in the fixture
function. If you only can decide about using another fixture at test
Declaring fixtures via function argument is recommended where possible.
But if you can only decide whether to use another fixture at test
setup time, you may use this function to retrieve it inside a fixture
function body.
or test function body.
"""
return self._get_active_fixturedef(argname).cached_result[0]

def getfuncargvalue(self, argname):
""" Deprecated, use getfixturevalue. """
warnings.warn(
"use of getfuncargvalue is deprecated, use getfixturevalue",
DeprecationWarning)
return self.getfixturevalue(argname)

def _get_active_fixturedef(self, argname):
try:
return self._fixturedefs[argname]
Expand All @@ -1624,7 +1631,7 @@ class PseudoFixtureDef:
raise
# remove indent to prevent the python3 exception
# from leaking into the call
result = self._getfuncargvalue(fixturedef)
result = self._getfixturevalue(fixturedef)
self._funcargs[argname] = result
self._fixturedefs[argname] = fixturedef
return fixturedef
Expand All @@ -1640,7 +1647,7 @@ def _get_fixturestack(self):
l.append(fixturedef)
current = current._parent_request

def _getfuncargvalue(self, fixturedef):
def _getfixturevalue(self, fixturedef):
# prepare a subrequest object before calling fixture function
# (latter managed by fixturedef)
argname = fixturedef.argname
Expand Down
15 changes: 12 additions & 3 deletions _pytest/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,15 @@ def pytest_addoption(parser):
group._addoption('-q', '--quiet', action="count",
dest="quiet", default=0, help="decrease verbosity."),
group._addoption('-r',
action="store", dest="reportchars", default=None, metavar="chars",
action="store", dest="reportchars", default='', metavar="chars",
help="show extra test summary info as specified by chars (f)ailed, "
"(E)error, (s)skipped, (x)failed, (X)passed (w)pytest-warnings "
"(p)passed, (P)passed with output, (a)all except pP.")
"(E)error, (s)skipped, (x)failed, (X)passed, "
"(p)passed, (P)passed with output, (a)all except pP. "
"The pytest warnings are displayed at all times except when "
"--disable-pytest-warnings is set")
group._addoption('--disable-pytest-warnings', default=False,
dest='disablepytestwarnings', action='store_true',
help='disable warnings summary, overrides -r w flag')
group._addoption('-l', '--showlocals',
action="store_true", dest="showlocals", default=False,
help="show locals in tracebacks (disabled by default).")
Expand Down Expand Up @@ -66,6 +71,10 @@ def getreportopt(config):
elif setting == "xfailed":
reportopts += "x"
reportchars = config.option.reportchars
if not config.option.disablepytestwarnings and 'w' not in reportchars:
reportchars += 'w'
elif config.option.disablepytestwarnings and 'w' in reportchars:
reportchars = reportchars.replace('w', '')
if reportchars:
for char in reportchars:
if char not in reportopts and char != 'a':
Expand Down
2 changes: 1 addition & 1 deletion doc/en/genapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def docmethod(self, method):

def pytest_funcarg__a(request):
with Writer("request") as writer:
writer.docmethod(request.getfuncargvalue)
writer.docmethod(request.getfixturevalue)
writer.docmethod(request.cached_setup)
writer.docmethod(request.addfinalizer)
writer.docmethod(request.applymarker)
Expand Down
2 changes: 1 addition & 1 deletion testing/code/test_excinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ class TestFormattedExcinfo:
def pytest_funcarg__importasmod(self, request):
def importasmod(source):
source = _pytest._code.Source(source)
tmpdir = request.getfuncargvalue("tmpdir")
tmpdir = request.getfixturevalue("tmpdir")
modpath = tmpdir.join("mod.py")
tmpdir.ensure("__init__.py")
modpath.write(source)
Expand Down
2 changes: 1 addition & 1 deletion testing/cx_freeze/runtests_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
setup(
name="runtests",
version="0.1",
description="exemple of how embedding py.test into an executable using cx_freeze",
description="example of how embedding py.test into an executable using cx_freeze",
executables=[Executable("runtests_script.py")],
options={"build_exe": {'includes': pytest.freeze_includes()}},
)
Expand Down
46 changes: 27 additions & 19 deletions testing/python/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ def test_conftest_funcargs_only_available_in_subdir(self, testdir):
sub1.join("conftest.py").write(_pytest._code.Source("""
import pytest
def pytest_funcarg__arg1(request):
pytest.raises(Exception, "request.getfuncargvalue('arg2')")
pytest.raises(Exception, "request.getfixturevalue('arg2')")
"""))
sub2.join("conftest.py").write(_pytest._code.Source("""
import pytest
def pytest_funcarg__arg2(request):
pytest.raises(Exception, "request.getfuncargvalue('arg1')")
pytest.raises(Exception, "request.getfixturevalue('arg1')")
"""))

sub1.join("test_in_sub1.py").write("def test_1(arg1): pass")
Expand Down Expand Up @@ -435,21 +435,23 @@ def test_method(self, something):
assert len(arg2fixturedefs) == 1
assert arg2fixturedefs[0].__name__ == "pytest_funcarg__something"

def test_getfuncargvalue_recursive(self, testdir):
def test_getfixturevalue_recursive(self, testdir):
testdir.makeconftest("""
def pytest_funcarg__something(request):
return 1
""")
testdir.makepyfile("""
def pytest_funcarg__something(request):
return request.getfuncargvalue("something") + 1
return request.getfixturevalue("something") + 1
def test_func(something):
assert something == 2
""")
reprec = testdir.inline_run()
reprec.assertoutcome(passed=1)

def test_getfuncargvalue(self, testdir):
@pytest.mark.parametrize(
'getfixmethod', ('getfixturevalue', 'getfuncargvalue'))
def test_getfixturevalue(self, testdir, getfixmethod):
item = testdir.getitem("""
l = [2]
def pytest_funcarg__something(request): return 1
Expand All @@ -458,14 +460,15 @@ def pytest_funcarg__other(request):
def test_func(something): pass
""")
req = item._request
pytest.raises(FixtureLookupError, req.getfuncargvalue, "notexists")
val = req.getfuncargvalue("something")
fixture_fetcher = getattr(req, getfixmethod)
pytest.raises(FixtureLookupError, fixture_fetcher, "notexists")
val = fixture_fetcher("something")
assert val == 1
val = req.getfuncargvalue("something")
val = fixture_fetcher("something")
assert val == 1
val2 = req.getfuncargvalue("other")
val2 = fixture_fetcher("other")
assert val2 == 2
val2 = req.getfuncargvalue("other") # see about caching
val2 = fixture_fetcher("other") # see about caching
assert val2 == 2
pytest._fillfuncargs(item)
assert item.funcargs["something"] == 1
Expand Down Expand Up @@ -812,10 +815,10 @@ def test_two_different_setups(arg1, arg2):
"*1 passed*"
])

def test_request_cached_setup_getfuncargvalue(self, testdir):
def test_request_cached_setup_getfixturevalue(self, testdir):
testdir.makepyfile("""
def pytest_funcarg__arg1(request):
arg1 = request.getfuncargvalue("arg2")
arg1 = request.getfixturevalue("arg2")
return request.cached_setup(lambda: arg1 + 1)
def pytest_funcarg__arg2(request):
return request.cached_setup(lambda: 10)
Expand Down Expand Up @@ -1118,7 +1121,7 @@ def test_2(arg2):

class TestFixtureManagerParseFactories:
def pytest_funcarg__testdir(self, request):
testdir = request.getfuncargvalue("testdir")
testdir = request.getfixturevalue("testdir")
testdir.makeconftest("""
def pytest_funcarg__hello(request):
return "conftest"
Expand Down Expand Up @@ -1804,9 +1807,9 @@ def test_4(arg, created, finalized):
reprec.assertoutcome(passed=4)

@pytest.mark.parametrize("method", [
'request.getfuncargvalue("arg")',
'request.getfixturevalue("arg")',
'request.cached_setup(lambda: None, scope="function")',
], ids=["getfuncargvalue", "cached_setup"])
], ids=["getfixturevalue", "cached_setup"])
def test_scope_mismatch_various(self, testdir, method):
testdir.makeconftest("""
import pytest
Expand Down Expand Up @@ -2737,6 +2740,7 @@ def test_1(arg1):
*def arg1*
""")


class TestParameterizedSubRequest:
def test_call_from_fixture(self, testdir):
testfile = testdir.makepyfile("""
Expand All @@ -2748,7 +2752,7 @@ def fix_with_param(request):

@pytest.fixture
def get_named_fixture(request):
return request.getfuncargvalue('fix_with_param')
return request.getfixturevalue('fix_with_param')

def test_foo(request, get_named_fixture):
pass
Expand All @@ -2773,7 +2777,7 @@ def fix_with_param(request):
return request.param

def test_foo(request):
request.getfuncargvalue('fix_with_param')
request.getfixturevalue('fix_with_param')
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines("""
Expand All @@ -2797,7 +2801,7 @@ def fix_with_param(request):

testfile = testdir.makepyfile("""
def test_foo(request):
request.getfuncargvalue('fix_with_param')
request.getfixturevalue('fix_with_param')
""")
result = testdir.runpytest()
result.stdout.fnmatch_lines("""
Expand Down Expand Up @@ -2827,7 +2831,7 @@ def fix_with_param(request):
from fix import fix_with_param

def test_foo(request):
request.getfuncargvalue('fix_with_param')
request.getfixturevalue('fix_with_param')
"""))

tests_dir.chdir()
Expand All @@ -2842,3 +2846,7 @@ def test_foo(request):
E*{1}:5
*1 failed*
""".format(fixfile.strpath, testfile.basename))


def test_getfuncargvalue_is_deprecated(request):
pytest.deprecated_call(request.getfuncargvalue, 'tmpdir')
Loading