diff --git a/CHANGELOG.rst b/CHANGELOG.rst index faaa6537498..aba7fa3eac6 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -146,13 +146,30 @@ * Add proposal to docs for a new feature that enables users to combine multiple fixtures into one. Thanks to `@hpk42`_ and `@hackebrot`_. +* 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. + +* Renamed the pytest ``pdb`` module (plugin) into ``debugging``. + * +* ImportErrors in plugins now are a fatal error instead of issuing a + pytest warning (`#1479`_). Thanks to `@The-Compiler`_ for the PR. + .. _#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 +.. _#1479: https://github.com/pytest-dev/pytest/issues/1479 .. _@graingert: https://github.com/graingert .. _@taschini: https://github.com/taschini @@ -166,6 +183,9 @@ ``--continue-on-collection-errors`` option to restore previous behaviour. Thanks `@olegpidsadnyi`_ and `@omarkohl`_ for the complete PR (`#1628`_). +.. _@bagerard: https://github.com/bagerard +.. _@davehunt: https://github.com/davehunt + * diff --git a/_pytest/assertion/util.py b/_pytest/assertion/util.py index 8bf425caf48..2481cf34ccd 100644 --- a/_pytest/assertion/util.py +++ b/_pytest/assertion/util.py @@ -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 diff --git a/_pytest/config.py b/_pytest/config.py index 72613d41f63..a2ff1eeab45 100644 --- a/_pytest/config.py +++ b/_pytest/config.py @@ -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 setuponly setupplan").split() @@ -655,20 +655,17 @@ def _set_opt_strings(self, opts): self._long_opts.append(opt) def __repr__(self): - retval = 'Argument(' + args = [] if self._short_opts: - retval += '_short_opts: ' + repr(self._short_opts) + ', ' + args += ['_short_opts: ' + repr(self._short_opts)] if self._long_opts: - retval += '_long_opts: ' + repr(self._long_opts) + ', ' - retval += 'dest: ' + repr(self.dest) + ', ' + args += ['_long_opts: ' + repr(self._long_opts)] + args += ['dest: ' + repr(self.dest)] if hasattr(self, 'type'): - retval += 'type: ' + repr(self.type) + ', ' + args += ['type: ' + repr(self.type)] if hasattr(self, 'default'): - retval += 'default: ' + repr(self.default) + ', ' - if retval[-2:] == ', ': # always long enough to test ("Argument(" ) - retval = retval[:-2] - retval += ')' - return retval + args += ['default: ' + repr(self.default)] + return 'Argument({0})'.format(', '.join(args)) class OptionGroup: @@ -927,10 +924,7 @@ def _preparse(self, args, addopts=True): args[:] = self.getini("addopts") + args self._checkversion() self.pluginmanager.consider_preparse(args) - try: - self.pluginmanager.load_setuptools_entrypoints("pytest11") - except ImportError as e: - self.warn("I2", "could not load setuptools entry import: %s" % (e,)) + self.pluginmanager.load_setuptools_entrypoints("pytest11") self.pluginmanager.consider_env() self.known_args_namespace = ns = self._parser.parse_known_args(args, namespace=self.option.copy()) if self.known_args_namespace.confcutdir is None and self.inifile: diff --git a/_pytest/pdb.py b/_pytest/debugging.py similarity index 100% rename from _pytest/pdb.py rename to _pytest/debugging.py diff --git a/_pytest/doctest.py b/_pytest/doctest.py index 4411158ab49..3702f8cbe15 100644 --- a/_pytest/doctest.py +++ b/_pytest/doctest.py @@ -70,8 +70,8 @@ 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) - for name, value in self.fixture_request.getfuncargvalue('doctest_namespace').items(): + globs = dict(getfixture=self.fixture_request.getfixturevalue) + for name, value in self.fixture_request.getfixturevalue('doctest_namespace').items(): globs[name] = value self.dtest.globs.update(globs) diff --git a/_pytest/python.py b/_pytest/python.py index a0624839bfc..62e598abf38 100644 --- a/_pytest/python.py +++ b/_pytest/python.py @@ -8,6 +8,7 @@ import sys import math import collections +import warnings import py import pytest @@ -1855,7 +1856,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) @@ -1950,7 +1951,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`` & @@ -1984,17 +1985,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] @@ -2010,7 +2017,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 @@ -2026,7 +2033,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 diff --git a/doc/en/_templates/layout.html b/doc/en/_templates/layout.html index 0ce480be300..2fc8e2a7fb4 100644 --- a/doc/en/_templates/layout.html +++ b/doc/en/_templates/layout.html @@ -1,19 +1,5 @@ {% extends "!layout.html" %} {% block header %} -
-

- Want to help improve pytest? Please - - contribute to - - or - - join - - our upcoming sprint in June 2016! - -

-
{{super()}} {% endblock %} {% block footer %} diff --git a/doc/en/_templates/links.html b/doc/en/_templates/links.html index 200258e165f..56486a750b8 100644 --- a/doc/en/_templates/links.html +++ b/doc/en/_templates/links.html @@ -1,10 +1,5 @@

Useful Links