Skip to content
Permalink
Browse files

Merge remote-tracking branch 'upstream/features'

  • Loading branch information...
nicoddemus committed Mar 23, 2018
2 parents fc4f769 + 5ecff65 commit ed118d7f2051ccfdb5c56cb6535e6f89485b1225
Showing with 2,499 additions and 899 deletions.
  1. +5 −0 AUTHORS
  2. +152 −0 CHANGELOG.rst
  3. +9 −7 _pytest/_code/code.py
  4. +13 −59 _pytest/_code/source.py
  5. +72 −18 _pytest/cacheprovider.py
  6. +54 −45 _pytest/config.py
  7. +10 −9 _pytest/debugging.py
  8. +13 −1 _pytest/deprecated.py
  9. +128 −45 _pytest/doctest.py
  10. +12 −5 _pytest/fixtures.py
  11. +8 −1 _pytest/hookspec.py
  12. +78 −20 _pytest/junitxml.py
  13. +30 −3 _pytest/logging.py
  14. +27 −4 _pytest/main.py
  15. +156 −0 _pytest/mark/__init__.py
  16. +126 −0 _pytest/mark/evaluate.py
  17. +97 −0 _pytest/mark/legacy.py
  18. +123 −302 _pytest/{mark.py → mark/structures.py}
  19. +33 −63 _pytest/nodes.py
  20. +1 −1 _pytest/python.py
  21. +40 −27 _pytest/python_api.py
  22. +14 −2 _pytest/runner.py
  23. +33 −143 _pytest/skipping.py
  24. +61 −25 _pytest/terminal.py
  25. +1 −0 changelog/1478.feature
  26. +1 −0 changelog/1642.feature.rst
  27. +1 −0 changelog/2405.feature.rst
  28. +2 −0 changelog/2770.feature
  29. +1 −0 changelog/2770.removal.rst
  30. +1 −0 changelog/3034.feature
  31. +1 −0 changelog/3084.removal
  32. +1 −0 changelog/3139.feature
  33. +1 −0 changelog/3149.feature
  34. +1 −0 changelog/3156.feature
  35. +1 −0 changelog/3189.feature
  36. +1 −0 changelog/3190.feature
  37. +1 −0 changelog/3198.feature.rst
  38. +1 −0 changelog/3204.feature
  39. +1 −0 changelog/3213.feature
  40. +1 −0 changelog/3228.trivial.rst
  41. +1 −0 changelog/3236.feature.rst
  42. +1 −0 changelog/3246.trival.rst
  43. +1 −0 changelog/3250.trivial.rst
  44. +1 −0 changelog/3255.feature.rst
  45. +1 −0 changelog/3265.trivial.rst
  46. +1 −0 changelog/3268.trivial
  47. +1 −0 changelog/3291.trivial.rst
  48. +1 −0 changelog/3292.trivial.rst
  49. +1 −0 changelog/3296.feature
  50. +1 −0 changelog/3296.trivial
  51. +1 −0 changelog/3304.trivial
  52. +1 −0 changelog/3312.feature
  53. +1 −0 changelog/3330.trivial.rst
  54. +1 −0 doc/en/announce/index.rst
  55. +51 −0 doc/en/announce/release-3.5.0.rst
  56. +100 −4 doc/en/builtin.rst
  57. +17 −2 doc/en/cache.rst
  58. +2 −1 doc/en/capture.rst
  59. +4 −0 doc/en/customize.rst
  60. +5 −0 doc/en/doctest.rst
  61. +8 −16 doc/en/example/markers.rst
  62. +8 −0 doc/en/example/pythoncollection.rst
  63. +1 −1 doc/en/example/reportingdemo.rst
  64. +5 −5 doc/en/example/simple.rst
  65. +48 −4 doc/en/fixture.rst
  66. +3 −19 doc/en/logging.rst
  67. +6 −0 doc/en/plugins.rst
  68. +3 −3 doc/en/reference.rst
  69. +0 −1 doc/en/tmpdir.rst
  70. +48 −14 doc/en/usage.rst
  71. +12 −0 doc/en/writing_plugins.rst
  72. +3 −2 setup.py
  73. +24 −0 testing/acceptance_test.py
  74. +76 −0 testing/deprecated_test.py
  75. +123 −1 testing/logging/test_reporting.py
  76. +22 −0 testing/python/approx.py
  77. +199 −14 testing/python/fixture.py
  78. +144 −5 testing/test_cacheprovider.py
  79. +21 −0 testing/test_doctest.py
  80. +28 −11 testing/test_junitxml.py
  81. +36 −0 testing/test_pdb.py
  82. +1 −1 testing/test_resultlog.py
  83. +44 −0 testing/test_session.py
  84. +40 −0 testing/test_skipping.py
  85. +88 −13 testing/test_terminal.py
  86. +3 −2 tox.ini
@@ -35,6 +35,7 @@ Brianna Laugher
Bruno Oliveira
Cal Leeming
Carl Friedrich Bolz
Carlos Jenkins
Ceridwen
Charles Cloud
Charnjit SiNGH (CCSJ)
@@ -99,6 +100,7 @@ Jon Sonesen
Jonas Obrist
Jordan Guymon
Jordan Moldow
Jordan Speicher
Joshua Bronson
Jurko Gospodnetić
Justyna Janczyszyn
@@ -146,11 +148,13 @@ Ned Batchelder
Neven Mundar
Nicolas Delaby
Oleg Pidsadnyi
Oleg Sushchenko
Oliver Bestwalter
Omar Kohl
Omer Hadari
Patrick Hayes
Paweł Adamczak
Pedro Algarvio
Pieter Mulder
Piotr Banaszkiewicz
Punyashloka Biswal
@@ -194,6 +198,7 @@ Victor Uriarte
Vidar T. Fauske
Vitaly Lashmanov
Vlad Dragos
William Lee
Wouter van Ackooy
Xuan Luong
Xuecong Liao
@@ -8,6 +8,158 @@
.. towncrier release notes start
Pytest 3.5.0 (2018-03-21)
=========================

Deprecations and Removals
-------------------------

- ``record_xml_property`` fixture is now deprecated in favor of the more
generic ``record_property``. (`#2770
<https://github.com/pytest-dev/pytest/issues/2770>`_)

- Defining ``pytest_plugins`` is now deprecated in non-top-level conftest.py
files, because they "leak" to the entire directory tree. (`#3084
<https://github.com/pytest-dev/pytest/issues/3084>`_)


Features
--------

- New ``--show-capture`` command-line option that allows to specify how to
display captured output when tests fail: ``no``, ``stdout``, ``stderr``,
``log`` or ``all`` (the default). (`#1478
<https://github.com/pytest-dev/pytest/issues/1478>`_)

- New ``--rootdir`` command-line option to override the rules for discovering
the root directory. See `customize
<https://docs.pytest.org/en/latest/customize.html>`_ in the documentation for
details. (`#1642 <https://github.com/pytest-dev/pytest/issues/1642>`_)

- Fixtures are now instantiated based on their scopes, with higher-scoped
fixtures (such as ``session``) being instantiated first than lower-scoped
fixtures (such as ``function``). The relative order of fixtures of the same
scope is kept unchanged, based in their declaration order and their
dependencies. (`#2405 <https://github.com/pytest-dev/pytest/issues/2405>`_)

- ``record_xml_property`` renamed to ``record_property`` and is now compatible
with xdist, markers and any reporter. ``record_xml_property`` name is now
deprecated. (`#2770 <https://github.com/pytest-dev/pytest/issues/2770>`_)

- New ``--nf``, ``--new-first`` options: run new tests first followed by the
rest of the tests, in both cases tests are also sorted by the file modified
time, with more recent files coming first. (`#3034
<https://github.com/pytest-dev/pytest/issues/3034>`_)

- New ``--last-failed-no-failures`` command-line option that allows to specify
the behavior of the cache plugin's ```--last-failed`` feature when no tests
failed in the last run (or no cache was found): ``none`` or ``all`` (the
default). (`#3139 <https://github.com/pytest-dev/pytest/issues/3139>`_)

- New ``--doctest-continue-on-failure`` command-line option to enable doctests
to show multiple failures for each snippet, instead of stopping at the first
failure. (`#3149 <https://github.com/pytest-dev/pytest/issues/3149>`_)

- Captured log messages are added to the ``<system-out>`` tag in the generated
junit xml file if the ``junit_logging`` ini option is set to ``system-out``.
If the value of this ini option is ``system-err`, the logs are written to
``<system-err>``. The default value for ``junit_logging`` is ``no``, meaning
captured logs are not written to the output file. (`#3156
<https://github.com/pytest-dev/pytest/issues/3156>`_)

- Allow the logging plugin to handle ``pytest_runtest_logstart`` and
``pytest_runtest_logfinish`` hooks when live logs are enabled. (`#3189
<https://github.com/pytest-dev/pytest/issues/3189>`_)

- Passing `--log-cli-level` in the command-line now automatically activates
live logging. (`#3190 <https://github.com/pytest-dev/pytest/issues/3190>`_)

- Add command line option ``--deselect`` to allow deselection of individual
tests at collection time. (`#3198
<https://github.com/pytest-dev/pytest/issues/3198>`_)

- Captured logs are printed before entering pdb. (`#3204
<https://github.com/pytest-dev/pytest/issues/3204>`_)

- Deselected item count is now shown before tests are run, e.g. ``collected X
items / Y deselected``. (`#3213
<https://github.com/pytest-dev/pytest/issues/3213>`_)

- The builtin module ``platform`` is now available for use in expressions in
``pytest.mark``. (`#3236
<https://github.com/pytest-dev/pytest/issues/3236>`_)

- The *short test summary info* section now is displayed after tracebacks and
warnings in the terminal. (`#3255
<https://github.com/pytest-dev/pytest/issues/3255>`_)

- New ``--verbosity`` flag to set verbosity level explicitly. (`#3296
<https://github.com/pytest-dev/pytest/issues/3296>`_)

- ``pytest.approx`` now accepts comparing a numpy array with a scalar. (`#3312
<https://github.com/pytest-dev/pytest/issues/3312>`_)


Bug Fixes
---------

- Suppress ``IOError`` when closing the temporary file used for capturing
streams in Python 2.7. (`#2370
<https://github.com/pytest-dev/pytest/issues/2370>`_)

- Fixed ``clear()`` method on ``caplog`` fixture which cleared ``records``, but
not the ``text`` property. (`#3297
<https://github.com/pytest-dev/pytest/issues/3297>`_)

- During test collection, when stdin is not allowed to be read, the
``DontReadFromStdin`` object still allow itself to be iterable and resolved
to an iterator without crashing. (`#3314
<https://github.com/pytest-dev/pytest/issues/3314>`_)


Improved Documentation
----------------------

- Added a `reference <https://docs.pytest.org/en/latest/reference.html>`_ page
to the docs. (`#1713 <https://github.com/pytest-dev/pytest/issues/1713>`_)


Trivial/Internal Changes
------------------------

- Change minimum requirement of ``attrs`` to ``17.4.0``. (`#3228
<https://github.com/pytest-dev/pytest/issues/3228>`_)

- Renamed example directories so all tests pass when ran from the base
directory. (`#3245 <https://github.com/pytest-dev/pytest/issues/3245>`_)

- Internal ``mark.py`` module has been turned into a package. (`#3250
<https://github.com/pytest-dev/pytest/issues/3250>`_)

- ``pytest`` now depends on the `more_itertools
<https://github.com/erikrose/more-itertools>`_ package. (`#3265
<https://github.com/pytest-dev/pytest/issues/3265>`_)

- Added warning when ``[pytest]`` section is used in a ``.cfg`` file passed
with ``-c`` (`#3268 <https://github.com/pytest-dev/pytest/issues/3268>`_)

- ``nodeids`` can now be passed explicitly to ``FSCollector`` and ``Node``
constructors. (`#3291 <https://github.com/pytest-dev/pytest/issues/3291>`_)

- Internal refactoring of ``FormattedExcinfo`` to use ``attrs`` facilities and
remove old support code for legacy Python versions. (`#3292
<https://github.com/pytest-dev/pytest/issues/3292>`_)

- Refactoring to unify how verbosity is handled internally. (`#3296
<https://github.com/pytest-dev/pytest/issues/3296>`_)

- Internal refactoring to better integrate with argparse. (`#3304
<https://github.com/pytest-dev/pytest/issues/3304>`_)

- Fix a python example when calling a fixture in doc/en/usage.rst (`#3308
<https://github.com/pytest-dev/pytest/issues/3308>`_)


Pytest 3.4.2 (2018-03-04)
=========================

@@ -3,6 +3,8 @@
import sys
import traceback
from inspect import CO_VARARGS, CO_VARKEYWORDS

import attr
import re
from weakref import ref
from _pytest.compat import _PY2, _PY3, PY35, safe_str
@@ -458,19 +460,19 @@ def match(self, regexp):
return True


@attr.s
class FormattedExcinfo(object):
""" presenting information about failing Functions and Generators. """
# for traceback entries
flow_marker = ">"
fail_marker = "E"

def __init__(self, showlocals=False, style="long", abspath=True, tbfilter=True, funcargs=False):
self.showlocals = showlocals
self.style = style
self.tbfilter = tbfilter
self.funcargs = funcargs
self.abspath = abspath
self.astcache = {}
showlocals = attr.ib(default=False)
style = attr.ib(default="long")
abspath = attr.ib(default=True)
tbfilter = attr.ib(default=True)
funcargs = attr.ib(default=False)
astcache = attr.ib(default=attr.Factory(dict), init=False, repr=False)

def _getindent(self, source):
# figure out indent for given source
@@ -26,7 +26,7 @@ def __init__(self, *parts, **kwargs):
for part in parts:
if not part:
partlines = []
if isinstance(part, Source):
elif isinstance(part, Source):
partlines = part.lines
elif isinstance(part, (tuple, list)):
partlines = [x.rstrip("\n") for x in part]
@@ -98,14 +98,14 @@ def indent(self, indent=' ' * 4):
newsource.lines = [(indent + line) for line in self.lines]
return newsource

def getstatement(self, lineno, assertion=False):
def getstatement(self, lineno):
""" return Source statement which contains the
given linenumber (counted from 0).
"""
start, end = self.getstatementrange(lineno, assertion)
start, end = self.getstatementrange(lineno)
return self[start:end]

def getstatementrange(self, lineno, assertion=False):
def getstatementrange(self, lineno):
""" return (start, end) tuple which spans the minimal
statement region which containing the given lineno.
"""
@@ -131,13 +131,7 @@ def isparseable(self, deindent=True):
""" return True if source is parseable, heuristically
deindenting it by default.
"""
try:
import parser
except ImportError:
def syntax_checker(x):
return compile(x, 'asd', 'exec')
else:
syntax_checker = parser.suite
from parser import suite as syntax_checker

if deindent:
source = str(self.deindent())
@@ -219,9 +213,9 @@ def getfslineno(obj):
""" Return source location (path, lineno) for the given object.
If the source cannot be determined return ("", -1)
"""
import _pytest._code
from .code import Code
try:
code = _pytest._code.Code(obj)
code = Code(obj)
except TypeError:
try:
fn = inspect.getsourcefile(obj) or inspect.getfile(obj)
@@ -259,8 +253,8 @@ def findsource(obj):


def getsource(obj, **kwargs):
import _pytest._code
obj = _pytest._code.getrawcode(obj)
from .code import getrawcode
obj = getrawcode(obj)
try:
strsrc = inspect.getsource(obj)
except IndentationError:
@@ -286,8 +280,6 @@ def deindent(lines, offset=None):
def readline_generator(lines):
for line in lines:
yield line + '\n'
while True:
yield ''

it = readline_generator(lines)

@@ -318,9 +310,9 @@ def get_statement_startend2(lineno, node):
# AST's line numbers start indexing at 1
values = []
for x in ast.walk(node):
if isinstance(x, ast.stmt) or isinstance(x, ast.ExceptHandler):
if isinstance(x, (ast.stmt, ast.ExceptHandler)):
values.append(x.lineno - 1)
for name in "finalbody", "orelse":
for name in ("finalbody", "orelse"):
val = getattr(x, name, None)
if val:
# treat the finally/orelse part as its own statement
@@ -338,11 +330,8 @@ def get_statement_startend2(lineno, node):
def getstatementrange_ast(lineno, source, assertion=False, astnode=None):
if astnode is None:
content = str(source)
try:
astnode = compile(content, "source", "exec", 1024) # 1024 for AST
except ValueError:
start, end = getstatementrange_old(lineno, source, assertion)
return None, start, end
astnode = compile(content, "source", "exec", 1024) # 1024 for AST

start, end = get_statement_startend2(lineno, astnode)
# we need to correct the end:
# - ast-parsing strips comments
@@ -374,38 +363,3 @@ def getstatementrange_ast(lineno, source, assertion=False, astnode=None):
else:
break
return astnode, start, end


def getstatementrange_old(lineno, source, assertion=False):
""" return (start, end) tuple which spans the minimal
statement region which containing the given lineno.
raise an IndexError if no such statementrange can be found.
"""
# XXX this logic is only used on python2.4 and below
# 1. find the start of the statement
from codeop import compile_command
for start in range(lineno, -1, -1):
if assertion:
line = source.lines[start]
# the following lines are not fully tested, change with care
if 'super' in line and 'self' in line and '__init__' in line:
raise IndexError("likely a subclass")
if "assert" not in line and "raise" not in line:
continue
trylines = source.lines[start:lineno + 1]
# quick hack to prepare parsing an indented line with
# compile_command() (which errors on "return" outside defs)
trylines.insert(0, 'def xxx():')
trysource = '\n '.join(trylines)
# ^ space here
try:
compile_command(trysource)
except (SyntaxError, OverflowError, ValueError):
continue

# 2. find the end of the statement
for end in range(lineno + 1, len(source) + 1):
trysource = source[start:end]
if trysource.isparseable():
return start, end
raise SyntaxError("no valid source range around line %d " % (lineno,))
Oops, something went wrong.

0 comments on commit ed118d7

Please sign in to comment.
You can’t perform that action at this time.