Skip to content

Commit ed118d7

Browse files
committed
Merge remote-tracking branch 'upstream/features'
2 parents fc4f769 + 5ecff65 commit ed118d7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2499
-899
lines changed

AUTHORS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Brianna Laugher
3535
Bruno Oliveira
3636
Cal Leeming
3737
Carl Friedrich Bolz
38+
Carlos Jenkins
3839
Ceridwen
3940
Charles Cloud
4041
Charnjit SiNGH (CCSJ)
@@ -99,6 +100,7 @@ Jon Sonesen
99100
Jonas Obrist
100101
Jordan Guymon
101102
Jordan Moldow
103+
Jordan Speicher
102104
Joshua Bronson
103105
Jurko Gospodnetić
104106
Justyna Janczyszyn
@@ -146,11 +148,13 @@ Ned Batchelder
146148
Neven Mundar
147149
Nicolas Delaby
148150
Oleg Pidsadnyi
151+
Oleg Sushchenko
149152
Oliver Bestwalter
150153
Omar Kohl
151154
Omer Hadari
152155
Patrick Hayes
153156
Paweł Adamczak
157+
Pedro Algarvio
154158
Pieter Mulder
155159
Piotr Banaszkiewicz
156160
Punyashloka Biswal
@@ -194,6 +198,7 @@ Victor Uriarte
194198
Vidar T. Fauske
195199
Vitaly Lashmanov
196200
Vlad Dragos
201+
William Lee
197202
Wouter van Ackooy
198203
Xuan Luong
199204
Xuecong Liao

CHANGELOG.rst

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,158 @@
88
99
.. towncrier release notes start
1010
11+
Pytest 3.5.0 (2018-03-21)
12+
=========================
13+
14+
Deprecations and Removals
15+
-------------------------
16+
17+
- ``record_xml_property`` fixture is now deprecated in favor of the more
18+
generic ``record_property``. (`#2770
19+
<https://github.com/pytest-dev/pytest/issues/2770>`_)
20+
21+
- Defining ``pytest_plugins`` is now deprecated in non-top-level conftest.py
22+
files, because they "leak" to the entire directory tree. (`#3084
23+
<https://github.com/pytest-dev/pytest/issues/3084>`_)
24+
25+
26+
Features
27+
--------
28+
29+
- New ``--show-capture`` command-line option that allows to specify how to
30+
display captured output when tests fail: ``no``, ``stdout``, ``stderr``,
31+
``log`` or ``all`` (the default). (`#1478
32+
<https://github.com/pytest-dev/pytest/issues/1478>`_)
33+
34+
- New ``--rootdir`` command-line option to override the rules for discovering
35+
the root directory. See `customize
36+
<https://docs.pytest.org/en/latest/customize.html>`_ in the documentation for
37+
details. (`#1642 <https://github.com/pytest-dev/pytest/issues/1642>`_)
38+
39+
- Fixtures are now instantiated based on their scopes, with higher-scoped
40+
fixtures (such as ``session``) being instantiated first than lower-scoped
41+
fixtures (such as ``function``). The relative order of fixtures of the same
42+
scope is kept unchanged, based in their declaration order and their
43+
dependencies. (`#2405 <https://github.com/pytest-dev/pytest/issues/2405>`_)
44+
45+
- ``record_xml_property`` renamed to ``record_property`` and is now compatible
46+
with xdist, markers and any reporter. ``record_xml_property`` name is now
47+
deprecated. (`#2770 <https://github.com/pytest-dev/pytest/issues/2770>`_)
48+
49+
- New ``--nf``, ``--new-first`` options: run new tests first followed by the
50+
rest of the tests, in both cases tests are also sorted by the file modified
51+
time, with more recent files coming first. (`#3034
52+
<https://github.com/pytest-dev/pytest/issues/3034>`_)
53+
54+
- New ``--last-failed-no-failures`` command-line option that allows to specify
55+
the behavior of the cache plugin's ```--last-failed`` feature when no tests
56+
failed in the last run (or no cache was found): ``none`` or ``all`` (the
57+
default). (`#3139 <https://github.com/pytest-dev/pytest/issues/3139>`_)
58+
59+
- New ``--doctest-continue-on-failure`` command-line option to enable doctests
60+
to show multiple failures for each snippet, instead of stopping at the first
61+
failure. (`#3149 <https://github.com/pytest-dev/pytest/issues/3149>`_)
62+
63+
- Captured log messages are added to the ``<system-out>`` tag in the generated
64+
junit xml file if the ``junit_logging`` ini option is set to ``system-out``.
65+
If the value of this ini option is ``system-err`, the logs are written to
66+
``<system-err>``. The default value for ``junit_logging`` is ``no``, meaning
67+
captured logs are not written to the output file. (`#3156
68+
<https://github.com/pytest-dev/pytest/issues/3156>`_)
69+
70+
- Allow the logging plugin to handle ``pytest_runtest_logstart`` and
71+
``pytest_runtest_logfinish`` hooks when live logs are enabled. (`#3189
72+
<https://github.com/pytest-dev/pytest/issues/3189>`_)
73+
74+
- Passing `--log-cli-level` in the command-line now automatically activates
75+
live logging. (`#3190 <https://github.com/pytest-dev/pytest/issues/3190>`_)
76+
77+
- Add command line option ``--deselect`` to allow deselection of individual
78+
tests at collection time. (`#3198
79+
<https://github.com/pytest-dev/pytest/issues/3198>`_)
80+
81+
- Captured logs are printed before entering pdb. (`#3204
82+
<https://github.com/pytest-dev/pytest/issues/3204>`_)
83+
84+
- Deselected item count is now shown before tests are run, e.g. ``collected X
85+
items / Y deselected``. (`#3213
86+
<https://github.com/pytest-dev/pytest/issues/3213>`_)
87+
88+
- The builtin module ``platform`` is now available for use in expressions in
89+
``pytest.mark``. (`#3236
90+
<https://github.com/pytest-dev/pytest/issues/3236>`_)
91+
92+
- The *short test summary info* section now is displayed after tracebacks and
93+
warnings in the terminal. (`#3255
94+
<https://github.com/pytest-dev/pytest/issues/3255>`_)
95+
96+
- New ``--verbosity`` flag to set verbosity level explicitly. (`#3296
97+
<https://github.com/pytest-dev/pytest/issues/3296>`_)
98+
99+
- ``pytest.approx`` now accepts comparing a numpy array with a scalar. (`#3312
100+
<https://github.com/pytest-dev/pytest/issues/3312>`_)
101+
102+
103+
Bug Fixes
104+
---------
105+
106+
- Suppress ``IOError`` when closing the temporary file used for capturing
107+
streams in Python 2.7. (`#2370
108+
<https://github.com/pytest-dev/pytest/issues/2370>`_)
109+
110+
- Fixed ``clear()`` method on ``caplog`` fixture which cleared ``records``, but
111+
not the ``text`` property. (`#3297
112+
<https://github.com/pytest-dev/pytest/issues/3297>`_)
113+
114+
- During test collection, when stdin is not allowed to be read, the
115+
``DontReadFromStdin`` object still allow itself to be iterable and resolved
116+
to an iterator without crashing. (`#3314
117+
<https://github.com/pytest-dev/pytest/issues/3314>`_)
118+
119+
120+
Improved Documentation
121+
----------------------
122+
123+
- Added a `reference <https://docs.pytest.org/en/latest/reference.html>`_ page
124+
to the docs. (`#1713 <https://github.com/pytest-dev/pytest/issues/1713>`_)
125+
126+
127+
Trivial/Internal Changes
128+
------------------------
129+
130+
- Change minimum requirement of ``attrs`` to ``17.4.0``. (`#3228
131+
<https://github.com/pytest-dev/pytest/issues/3228>`_)
132+
133+
- Renamed example directories so all tests pass when ran from the base
134+
directory. (`#3245 <https://github.com/pytest-dev/pytest/issues/3245>`_)
135+
136+
- Internal ``mark.py`` module has been turned into a package. (`#3250
137+
<https://github.com/pytest-dev/pytest/issues/3250>`_)
138+
139+
- ``pytest`` now depends on the `more_itertools
140+
<https://github.com/erikrose/more-itertools>`_ package. (`#3265
141+
<https://github.com/pytest-dev/pytest/issues/3265>`_)
142+
143+
- Added warning when ``[pytest]`` section is used in a ``.cfg`` file passed
144+
with ``-c`` (`#3268 <https://github.com/pytest-dev/pytest/issues/3268>`_)
145+
146+
- ``nodeids`` can now be passed explicitly to ``FSCollector`` and ``Node``
147+
constructors. (`#3291 <https://github.com/pytest-dev/pytest/issues/3291>`_)
148+
149+
- Internal refactoring of ``FormattedExcinfo`` to use ``attrs`` facilities and
150+
remove old support code for legacy Python versions. (`#3292
151+
<https://github.com/pytest-dev/pytest/issues/3292>`_)
152+
153+
- Refactoring to unify how verbosity is handled internally. (`#3296
154+
<https://github.com/pytest-dev/pytest/issues/3296>`_)
155+
156+
- Internal refactoring to better integrate with argparse. (`#3304
157+
<https://github.com/pytest-dev/pytest/issues/3304>`_)
158+
159+
- Fix a python example when calling a fixture in doc/en/usage.rst (`#3308
160+
<https://github.com/pytest-dev/pytest/issues/3308>`_)
161+
162+
11163
Pytest 3.4.2 (2018-03-04)
12164
=========================
13165

_pytest/_code/code.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import sys
44
import traceback
55
from inspect import CO_VARARGS, CO_VARKEYWORDS
6+
7+
import attr
68
import re
79
from weakref import ref
810
from _pytest.compat import _PY2, _PY3, PY35, safe_str
@@ -458,19 +460,19 @@ def match(self, regexp):
458460
return True
459461

460462

463+
@attr.s
461464
class FormattedExcinfo(object):
462465
""" presenting information about failing Functions and Generators. """
463466
# for traceback entries
464467
flow_marker = ">"
465468
fail_marker = "E"
466469

467-
def __init__(self, showlocals=False, style="long", abspath=True, tbfilter=True, funcargs=False):
468-
self.showlocals = showlocals
469-
self.style = style
470-
self.tbfilter = tbfilter
471-
self.funcargs = funcargs
472-
self.abspath = abspath
473-
self.astcache = {}
470+
showlocals = attr.ib(default=False)
471+
style = attr.ib(default="long")
472+
abspath = attr.ib(default=True)
473+
tbfilter = attr.ib(default=True)
474+
funcargs = attr.ib(default=False)
475+
astcache = attr.ib(default=attr.Factory(dict), init=False, repr=False)
474476

475477
def _getindent(self, source):
476478
# figure out indent for given source

_pytest/_code/source.py

Lines changed: 13 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __init__(self, *parts, **kwargs):
2626
for part in parts:
2727
if not part:
2828
partlines = []
29-
if isinstance(part, Source):
29+
elif isinstance(part, Source):
3030
partlines = part.lines
3131
elif isinstance(part, (tuple, list)):
3232
partlines = [x.rstrip("\n") for x in part]
@@ -98,14 +98,14 @@ def indent(self, indent=' ' * 4):
9898
newsource.lines = [(indent + line) for line in self.lines]
9999
return newsource
100100

101-
def getstatement(self, lineno, assertion=False):
101+
def getstatement(self, lineno):
102102
""" return Source statement which contains the
103103
given linenumber (counted from 0).
104104
"""
105-
start, end = self.getstatementrange(lineno, assertion)
105+
start, end = self.getstatementrange(lineno)
106106
return self[start:end]
107107

108-
def getstatementrange(self, lineno, assertion=False):
108+
def getstatementrange(self, lineno):
109109
""" return (start, end) tuple which spans the minimal
110110
statement region which containing the given lineno.
111111
"""
@@ -131,13 +131,7 @@ def isparseable(self, deindent=True):
131131
""" return True if source is parseable, heuristically
132132
deindenting it by default.
133133
"""
134-
try:
135-
import parser
136-
except ImportError:
137-
def syntax_checker(x):
138-
return compile(x, 'asd', 'exec')
139-
else:
140-
syntax_checker = parser.suite
134+
from parser import suite as syntax_checker
141135

142136
if deindent:
143137
source = str(self.deindent())
@@ -219,9 +213,9 @@ def getfslineno(obj):
219213
""" Return source location (path, lineno) for the given object.
220214
If the source cannot be determined return ("", -1)
221215
"""
222-
import _pytest._code
216+
from .code import Code
223217
try:
224-
code = _pytest._code.Code(obj)
218+
code = Code(obj)
225219
except TypeError:
226220
try:
227221
fn = inspect.getsourcefile(obj) or inspect.getfile(obj)
@@ -259,8 +253,8 @@ def findsource(obj):
259253

260254

261255
def getsource(obj, **kwargs):
262-
import _pytest._code
263-
obj = _pytest._code.getrawcode(obj)
256+
from .code import getrawcode
257+
obj = getrawcode(obj)
264258
try:
265259
strsrc = inspect.getsource(obj)
266260
except IndentationError:
@@ -286,8 +280,6 @@ def deindent(lines, offset=None):
286280
def readline_generator(lines):
287281
for line in lines:
288282
yield line + '\n'
289-
while True:
290-
yield ''
291283

292284
it = readline_generator(lines)
293285

@@ -318,9 +310,9 @@ def get_statement_startend2(lineno, node):
318310
# AST's line numbers start indexing at 1
319311
values = []
320312
for x in ast.walk(node):
321-
if isinstance(x, ast.stmt) or isinstance(x, ast.ExceptHandler):
313+
if isinstance(x, (ast.stmt, ast.ExceptHandler)):
322314
values.append(x.lineno - 1)
323-
for name in "finalbody", "orelse":
315+
for name in ("finalbody", "orelse"):
324316
val = getattr(x, name, None)
325317
if val:
326318
# treat the finally/orelse part as its own statement
@@ -338,11 +330,8 @@ def get_statement_startend2(lineno, node):
338330
def getstatementrange_ast(lineno, source, assertion=False, astnode=None):
339331
if astnode is None:
340332
content = str(source)
341-
try:
342-
astnode = compile(content, "source", "exec", 1024) # 1024 for AST
343-
except ValueError:
344-
start, end = getstatementrange_old(lineno, source, assertion)
345-
return None, start, end
333+
astnode = compile(content, "source", "exec", 1024) # 1024 for AST
334+
346335
start, end = get_statement_startend2(lineno, astnode)
347336
# we need to correct the end:
348337
# - ast-parsing strips comments
@@ -374,38 +363,3 @@ def getstatementrange_ast(lineno, source, assertion=False, astnode=None):
374363
else:
375364
break
376365
return astnode, start, end
377-
378-
379-
def getstatementrange_old(lineno, source, assertion=False):
380-
""" return (start, end) tuple which spans the minimal
381-
statement region which containing the given lineno.
382-
raise an IndexError if no such statementrange can be found.
383-
"""
384-
# XXX this logic is only used on python2.4 and below
385-
# 1. find the start of the statement
386-
from codeop import compile_command
387-
for start in range(lineno, -1, -1):
388-
if assertion:
389-
line = source.lines[start]
390-
# the following lines are not fully tested, change with care
391-
if 'super' in line and 'self' in line and '__init__' in line:
392-
raise IndexError("likely a subclass")
393-
if "assert" not in line and "raise" not in line:
394-
continue
395-
trylines = source.lines[start:lineno + 1]
396-
# quick hack to prepare parsing an indented line with
397-
# compile_command() (which errors on "return" outside defs)
398-
trylines.insert(0, 'def xxx():')
399-
trysource = '\n '.join(trylines)
400-
# ^ space here
401-
try:
402-
compile_command(trysource)
403-
except (SyntaxError, OverflowError, ValueError):
404-
continue
405-
406-
# 2. find the end of the statement
407-
for end in range(lineno + 1, len(source) + 1):
408-
trysource = source[start:end]
409-
if trysource.isparseable():
410-
return start, end
411-
raise SyntaxError("no valid source range around line %d " % (lineno,))

0 commit comments

Comments
 (0)