Skip to content

Commit

Permalink
Merge branch 'features' into feat/junitxml/suite-name
Browse files Browse the repository at this point in the history
  • Loading branch information
dimp-gh committed Feb 22, 2017
2 parents 6db84b5 + 44ad369 commit 31b7632
Show file tree
Hide file tree
Showing 89 changed files with 1,115 additions and 583 deletions.
6 changes: 6 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Lukas Bednar
Luke Murphy
Maciek Fijalkowski
Maho
Mandeep Bhutani
Manuel Krebber
Marc Schlaich
Marcin Bachry
Mark Abramowitz
Expand All @@ -99,13 +101,15 @@ Martin K. Scherer
Martin Prusse
Mathieu Clabaut
Matt Bachmann
Matt Duck
Matt Williams
Matthias Hafner
mbyt
Michael Aquilina
Michael Birtwell
Michael Droettboom
Michael Seifert
Michal Wajszczuk
Mike Lundy
Ned Batchelder
Neven Mundar
Expand All @@ -121,6 +125,7 @@ Ralf Schmitt
Ran Benita
Raphael Pierzina
Raquel Alegre
Ravi Chandra
Roberto Polli
Romain Dorgueil
Roman Bolshakov
Expand All @@ -144,5 +149,6 @@ Tyler Goodlet
Vasily Kuznetsov
Victor Uriarte
Vidar T. Fauske
Vlad Dragos
Wouter van Ackooy
Xuecong Liao
79 changes: 79 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,80 @@
3.1.0.dev (unreleased)
======================


New Features
------------

* Added an ini option ``doctest_encoding`` to specify which encoding to use for doctest files.
Thanks `@wheerd`_ for the PR (`#2101`_).

* pytest now warns when a callable ids raises in a parametrized test. Thanks `@fogo`_ for the PR.

* ``pytest.warns`` now checks for subclass relationship rather than
class equality. Thanks `@lesteve`_ for the PR (`#2166`_)

* ``pytest.raises`` now asserts that the error message matches a text or regex
with the ``match`` keyword argument. Thanks `@Kriechi`_ for the PR.


Changes
-------

* Old-style classes have been changed to new-style classes in order to improve
compatibility with Python 2. Thanks to `@MichalTHEDUDE`_ and `@mandeep`_ for the PR (`#2147`_).

* It is now possible to skip test classes from being collected by setting a
``__test__`` attribute to ``False`` in the class body (`#2007`_). Thanks
to `@syre`_ for the report and `@lwm`_ for the PR.

* Testcase reports with a ``url`` attribute will now properly write this to junitxml.
Thanks `@fushi`_ for the PR (`#1874`_).

* Remove common items from dict comparision output when verbosity=1. Also update
the truncation message to make it clearer that pytest truncates all
assertion messages if verbosity < 2 (`#1512`_).
Thanks `@mattduck`_ for the PR

* ``--pdbcls`` no longer implies ``--pdb``. This makes it possible to use
``addopts=--pdbcls=module.SomeClass`` on ``pytest.ini``. Thanks `@davidszotten`_ for
the PR (`#1952`_).
* Change exception raised by ``capture.DontReadFromInput.fileno()`` from ``ValueError``
to ``io.UnsupportedOperation``. Thanks `@vlad-dragos`_ for the PR.

* fix `#2013`_: turn RecordedWarning into namedtupe,
to give it a comprehensible repr while preventing unwarranted modification

* fix `#2208`_: ensure a iteration limit for _pytest.compat.get_real_func.
Thanks `@RonnyPfannschmidt`_ for the Report and PR

* Modify ``pytest_make_parametrize_id()`` hook to accept ``argname`` as an
additional parameter.
Thanks `@unsignedint`_ for the PR.

* Add ``venv`` to the default ``norecursedirs`` setting.
Thanks `@The-Compiler`_ for the PR.


.. _@davidszotten: https://github.com/davidszotten
.. _@fushi: https://github.com/fushi
.. _@mattduck: https://github.com/mattduck
.. _@wheerd: https://github.com/wheerd
.. _@fogo: https://github.com/fogo
.. _@mandeep: https://github.com/mandeep
.. _@MichalTHEDUDE: https://github.com/MichalTHEDUDE
.. _@unsignedint: https://github.com/unsignedint
.. _@Kriechi: https://github.com/Kriechi

.. _#1512: https://github.com/pytest-dev/pytest/issues/1512
.. _#1874: https://github.com/pytest-dev/pytest/pull/1874
.. _#1952: https://github.com/pytest-dev/pytest/pull/1952
.. _#2007: https://github.com/pytest-dev/pytest/issues/2007
.. _#2013: https://github.com/pytest-dev/pytest/issues/2013
.. _#2101: https://github.com/pytest-dev/pytest/pull/2101
.. _#2166: https://github.com/pytest-dev/pytest/pull/2166
.. _#2147: https://github.com/pytest-dev/pytest/issues/2147
.. _#2208: https://github.com/pytest-dev/pytest/issues/2208

3.0.7 (unreleased)
==================

Expand Down Expand Up @@ -140,6 +217,7 @@
* Cope gracefully with a .pyc file with no matching .py file (`#2038`_). Thanks
`@nedbat`_.

.. _@syre: https://github.com/syre
.. _@adler-j: https://github.com/adler-j
.. _@d-b-w: https://bitbucket.org/d-b-w/
.. _@DuncanBetts: https://github.com/DuncanBetts
Expand Down Expand Up @@ -247,6 +325,7 @@
.. _@raquel-ucl: https://github.com/raquel-ucl
.. _@axil: https://github.com/axil
.. _@tgoodlet: https://github.com/tgoodlet
.. _@vlad-dragos: https://github.com/vlad-dragos

.. _#1853: https://github.com/pytest-dev/pytest/issues/1853
.. _#1905: https://github.com/pytest-dev/pytest/issues/1905
Expand Down
2 changes: 1 addition & 1 deletion _pytest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#
__version__ = '3.0.7.dev0'
__version__ = '3.1.0.dev0'
2 changes: 1 addition & 1 deletion _pytest/_argcomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
import os
from glob import glob

class FastFilesCompleter:
class FastFilesCompleter(object):
'Fast file completer class'
def __init__(self, directories=True):
self.directories = directories
Expand Down
23 changes: 5 additions & 18 deletions _pytest/assertion/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
support for presenting detailed information in failing assertions.
"""
import py
import os
import sys

from _pytest.assertion import util
from _pytest.assertion import rewrite
from _pytest.assertion import truncate


def pytest_addoption(parser):
Expand Down Expand Up @@ -59,7 +59,7 @@ def mark_rewrite(self, *names):
pass


class AssertionState:
class AssertionState(object):
"""State for the assertion plugin."""

def __init__(self, config, mode):
Expand Down Expand Up @@ -100,12 +100,6 @@ def pytest_collection(session):
assertstate.hook.set_session(session)


def _running_on_ci():
"""Check if we're currently running on a CI system."""
env_vars = ['CI', 'BUILD_NUMBER']
return any(var in os.environ for var in env_vars)


def pytest_runtest_setup(item):
"""Setup the pytest_assertrepr_compare hook
Expand All @@ -119,8 +113,8 @@ def callbinrepr(op, left, right):
This uses the first result from the hook and then ensures the
following:
* Overly verbose explanations are dropped unless -vv was used or
running on a CI.
* Overly verbose explanations are truncated unless configured otherwise
(eg. if running in verbose mode).
* Embedded newlines are escaped to help util.format_explanation()
later.
* If the rewrite mode is used embedded %-characters are replaced
Expand All @@ -133,14 +127,7 @@ def callbinrepr(op, left, right):
config=item.config, op=op, left=left, right=right)
for new_expl in hook_result:
if new_expl:
if (sum(len(p) for p in new_expl[1:]) > 80*8 and
item.config.option.verbose < 2 and
not _running_on_ci()):
show_max = 10
truncated_lines = len(new_expl) - show_max
new_expl[show_max:] = [py.builtin._totext(
'Detailed information truncated (%d more lines)'
', use "-vv" to show' % truncated_lines)]
new_expl = truncate.truncate_if_required(new_expl, item)
new_expl = [line.replace("\n", "\\n") for line in new_expl]
res = py.builtin._totext("\n~").join(new_expl)
if item.config.getvalue("assertmode") == "rewrite":
Expand Down
102 changes: 102 additions & 0 deletions _pytest/assertion/truncate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""
Utilities for truncating assertion output.
Current default behaviour is to truncate assertion explanations at
~8 terminal lines, unless running in "-vv" mode or running on CI.
"""

import os

import py


DEFAULT_MAX_LINES = 8
DEFAULT_MAX_CHARS = 8 * 80
USAGE_MSG = "use '-vv' to show"


def truncate_if_required(explanation, item, max_length=None):
"""
Truncate this assertion explanation if the given test item is eligible.
"""
if _should_truncate_item(item):
return _truncate_explanation(explanation)
return explanation


def _should_truncate_item(item):
"""
Whether or not this test item is eligible for truncation.
"""
verbose = item.config.option.verbose
return verbose < 2 and not _running_on_ci()


def _running_on_ci():
"""Check if we're currently running on a CI system."""
env_vars = ['CI', 'BUILD_NUMBER']
return any(var in os.environ for var in env_vars)


def _truncate_explanation(input_lines, max_lines=None, max_chars=None):
"""
Truncate given list of strings that makes up the assertion explanation.
Truncates to either 8 lines, or 640 characters - whichever the input reaches
first. The remaining lines will be replaced by a usage message.
"""

if max_lines is None:
max_lines = DEFAULT_MAX_LINES
if max_chars is None:
max_chars = DEFAULT_MAX_CHARS

# Check if truncation required
input_char_count = len("".join(input_lines))
if len(input_lines) <= max_lines and input_char_count <= max_chars:
return input_lines

# Truncate first to max_lines, and then truncate to max_chars if max_chars
# is exceeded.
truncated_explanation = input_lines[:max_lines]
truncated_explanation = _truncate_by_char_count(truncated_explanation, max_chars)

# Add ellipsis to final line
truncated_explanation[-1] = truncated_explanation[-1] + "..."

# Append useful message to explanation
truncated_line_count = len(input_lines) - len(truncated_explanation)
truncated_line_count += 1 # Account for the part-truncated final line
msg = '...Full output truncated'
if truncated_line_count == 1:
msg += ' ({0} line hidden)'.format(truncated_line_count)
else:
msg += ' ({0} lines hidden)'.format(truncated_line_count)
msg += ", {0}" .format(USAGE_MSG)
truncated_explanation.extend([
py.builtin._totext(""),
py.builtin._totext(msg),
])
return truncated_explanation


def _truncate_by_char_count(input_lines, max_chars):
# Check if truncation required
if len("".join(input_lines)) <= max_chars:
return input_lines

# Find point at which input length exceeds total allowed length
iterated_char_count = 0
for iterated_index, input_line in enumerate(input_lines):
if iterated_char_count + len(input_line) > max_chars:
break
iterated_char_count += len(input_line)

# Create truncated explanation with modified final line
truncated_result = input_lines[:iterated_index]
final_line = input_lines[iterated_index]
if final_line:
final_line_truncate_point = max_chars - iterated_char_count
final_line = final_line[:final_line_truncate_point]
truncated_result.append(final_line)
return truncated_result
6 changes: 3 additions & 3 deletions _pytest/assertion/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
except ImportError:
Sequence = list

BuiltinAssertionError = py.builtin.builtins.AssertionError

u = py.builtin._totext

# The _reprcompare attribute on the util module is used by the new assertion
Expand Down Expand Up @@ -256,8 +256,8 @@ def _compare_eq_dict(left, right, verbose=False):
explanation = []
common = set(left).intersection(set(right))
same = dict((k, left[k]) for k in common if left[k] == right[k])
if same and not verbose:
explanation += [u('Omitting %s identical items, use -v to show') %
if same and verbose < 2:
explanation += [u('Omitting %s identical items, use -vv to show') %
len(same)]
elif same:
explanation += [u('Common items:')]
Expand Down
2 changes: 1 addition & 1 deletion _pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def set(self, key, value):
json.dump(value, f, indent=2, sort_keys=True)


class LFPlugin:
class LFPlugin(object):
""" Plugin which implements the --lf (run last-failing) option """
def __init__(self, config):
self.config = config
Expand Down
Loading

0 comments on commit 31b7632

Please sign in to comment.