Skip to content

Commit 0a15edd

Browse files
committed
Merge branch 'release-3.2.0'
2 parents 51ebad7 + d2bca93 commit 0a15edd

Some content is hidden

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

69 files changed

+2096
-875
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ env:
1717
- TOXENV=py27-pexpect
1818
- TOXENV=py27-xdist
1919
- TOXENV=py27-trial
20+
- TOXENV=py27-numpy
2021
- TOXENV=py35-pexpect
2122
- TOXENV=py35-xdist
2223
- TOXENV=py35-trial
24+
- TOXENV=py35-numpy
2325
- TOXENV=py27-nobyte
2426
- TOXENV=doctesting
2527
- TOXENV=freeze

AUTHORS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,15 @@ John Towler
8484
Jon Sonesen
8585
Jonas Obrist
8686
Jordan Guymon
87+
Jordan Moldow
8788
Joshua Bronson
8889
Jurko Gospodnetić
8990
Justyna Janczyszyn
9091
Kale Kundert
9192
Katarzyna Jachim
9293
Kevin Cox
9394
Kodi B. Arfer
95+
Lawrence Mitchell
9496
Lee Kamentsky
9597
Lev Maximov
9698
Llandy Riveron Del Risco
@@ -99,6 +101,7 @@ Lukas Bednar
99101
Luke Murphy
100102
Maciek Fijalkowski
101103
Maho
104+
Maik Figura
102105
Mandeep Bhutani
103106
Manuel Krebber
104107
Marc Schlaich
@@ -122,6 +125,7 @@ Michael Seifert
122125
Michal Wajszczuk
123126
Mihai Capotă
124127
Mike Lundy
128+
Nathaniel Waisbrot
125129
Ned Batchelder
126130
Neven Mundar
127131
Nicolas Delaby

CHANGELOG.rst

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,172 @@
88
99
.. towncrier release notes start
1010
11+
Pytest 3.2.0 (2017-07-30)
12+
=========================
13+
14+
Deprecations and Removals
15+
-------------------------
16+
17+
- ``pytest.approx`` no longer supports ``>``, ``>=``, ``<`` and ``<=``
18+
operators to avoid surprising/inconsistent behavior. See `the docs
19+
<https://docs.pytest.org/en/latest/builtin.html#pytest.approx>`_ for more
20+
information. (`#2003 <https://github.com/pytest-dev/pytest/issues/2003>`_)
21+
22+
- All old-style specific behavior in current classes in the pytest's API is
23+
considered deprecated at this point and will be removed in a future release.
24+
This affects Python 2 users only and in rare situations. (`#2147
25+
<https://github.com/pytest-dev/pytest/issues/2147>`_)
26+
27+
- A deprecation warning is now raised when using marks for parameters
28+
in ``pytest.mark.parametrize``. Use ``pytest.param`` to apply marks to
29+
parameters instead. (`#2427 <https://github.com/pytest-dev/pytest/issues/2427>`_)
30+
31+
32+
Features
33+
--------
34+
35+
- Add support for numpy arrays (and dicts) to approx. (`#1994
36+
<https://github.com/pytest-dev/pytest/issues/1994>`_)
37+
38+
- Now test function objects have a ``pytestmark`` attribute containing a list
39+
of marks applied directly to the test function, as opposed to marks inherited
40+
from parent classes or modules. (`#2516 <https://github.com/pytest-
41+
dev/pytest/issues/2516>`_)
42+
43+
- Collection ignores local virtualenvs by default; `--collect-in-virtualenv`
44+
overrides this behavior. (`#2518 <https://github.com/pytest-
45+
dev/pytest/issues/2518>`_)
46+
47+
- Allow class methods decorated as ``@staticmethod`` to be candidates for
48+
collection as a test function. (Only for Python 2.7 and above. Python 2.6
49+
will still ignore static methods.) (`#2528 <https://github.com/pytest-
50+
dev/pytest/issues/2528>`_)
51+
52+
- Introduce ``mark.with_args`` in order to allow passing functions/classes as
53+
sole argument to marks. (`#2540 <https://github.com/pytest-
54+
dev/pytest/issues/2540>`_)
55+
56+
- New ``cache_dir`` ini option: sets the directory where the contents of the
57+
cache plugin are stored. Directory may be relative or absolute path: if relative path, then
58+
directory is created relative to ``rootdir``, otherwise it is used as is.
59+
Additionally path may contain environment variables which are expanded during
60+
runtime. (`#2543 <https://github.com/pytest-dev/pytest/issues/2543>`_)
61+
62+
- Introduce the ``PYTEST_CURRENT_TEST`` environment variable that is set with
63+
the ``nodeid`` and stage (``setup``, ``call`` and ``teardown``) of the test
64+
being currently executed. See the `documentation
65+
<https://docs.pytest.org/en/latest/example/simple.html#pytest-current-test-
66+
environment-variable>`_ for more info. (`#2583 <https://github.com/pytest-
67+
dev/pytest/issues/2583>`_)
68+
69+
- Introduced ``@pytest.mark.filterwarnings`` mark which allows overwriting the
70+
warnings filter on a per test, class or module level. See the `docs
71+
<https://docs.pytest.org/en/latest/warnings.html#pytest-mark-
72+
filterwarnings>`_ for more information. (`#2598 <https://github.com/pytest-
73+
dev/pytest/issues/2598>`_)
74+
75+
- ``--last-failed`` now remembers forever when a test has failed and only
76+
forgets it if it passes again. This makes it easy to fix a test suite by
77+
selectively running files and fixing tests incrementally. (`#2621
78+
<https://github.com/pytest-dev/pytest/issues/2621>`_)
79+
80+
- New ``pytest_report_collectionfinish`` hook which allows plugins to add
81+
messages to the terminal reporting after collection has been finished
82+
successfully. (`#2622 <https://github.com/pytest-dev/pytest/issues/2622>`_)
83+
84+
- Added support for `PEP-415's <https://www.python.org/dev/peps/pep-0415/>`_
85+
``Exception.__suppress_context__``. Now if a ``raise exception from None`` is
86+
caught by pytest, pytest will no longer chain the context in the test report.
87+
The behavior now matches Python's traceback behavior. (`#2631
88+
<https://github.com/pytest-dev/pytest/issues/2631>`_)
89+
90+
- Exceptions raised by ``pytest.fail``, ``pytest.skip`` and ``pytest.xfail``
91+
now subclass BaseException, making them harder to be caught unintentionally
92+
by normal code. (`#580 <https://github.com/pytest-dev/pytest/issues/580>`_)
93+
94+
95+
Bug Fixes
96+
---------
97+
98+
- Set ``stdin`` to a closed ``PIPE`` in ``pytester.py.Testdir.popen()`` for
99+
avoid unwanted interactive ``pdb`` (`#2023 <https://github.com/pytest-
100+
dev/pytest/issues/2023>`_)
101+
102+
- Add missing ``encoding`` attribute to ``sys.std*`` streams when using
103+
``capsys`` capture mode. (`#2375 <https://github.com/pytest-
104+
dev/pytest/issues/2375>`_)
105+
106+
- Fix terminal color changing to black on Windows if ``colorama`` is imported
107+
in a ``conftest.py`` file. (`#2510 <https://github.com/pytest-
108+
dev/pytest/issues/2510>`_)
109+
110+
- Fix line number when reporting summary of skipped tests. (`#2548
111+
<https://github.com/pytest-dev/pytest/issues/2548>`_)
112+
113+
- capture: ensure that EncodedFile.name is a string. (`#2555
114+
<https://github.com/pytest-dev/pytest/issues/2555>`_)
115+
116+
- The options ```--fixtures`` and ```--fixtures-per-test`` will now keep
117+
indentation within docstrings. (`#2574 <https://github.com/pytest-
118+
dev/pytest/issues/2574>`_)
119+
120+
- doctests line numbers are now reported correctly, fixing `pytest-sugar#122
121+
<https://github.com/Frozenball/pytest-sugar/issues/122>`_. (`#2610
122+
<https://github.com/pytest-dev/pytest/issues/2610>`_)
123+
124+
- Fix non-determinism in order of fixture collection. Adds new dependency
125+
(ordereddict) for Python 2.6. (`#920 <https://github.com/pytest-
126+
dev/pytest/issues/920>`_)
127+
128+
129+
Improved Documentation
130+
----------------------
131+
132+
- Clarify ``pytest_configure`` hook call order. (`#2539
133+
<https://github.com/pytest-dev/pytest/issues/2539>`_)
134+
135+
- Extend documentation for testing plugin code with the ``pytester`` plugin.
136+
(`#971 <https://github.com/pytest-dev/pytest/issues/971>`_)
137+
138+
139+
Trivial/Internal Changes
140+
------------------------
141+
142+
- Update help message for ``--strict`` to make it clear it only deals with
143+
unregistered markers, not warnings. (`#2444 <https://github.com/pytest-
144+
dev/pytest/issues/2444>`_)
145+
146+
- Internal code move: move code for pytest.approx/pytest.raises to own files in
147+
order to cut down the size of python.py (`#2489 <https://github.com/pytest-
148+
dev/pytest/issues/2489>`_)
149+
150+
- Renamed the utility function ``_pytest.compat._escape_strings`` to
151+
``_ascii_escaped`` to better communicate the function's purpose. (`#2533
152+
<https://github.com/pytest-dev/pytest/issues/2533>`_)
153+
154+
- Improve error message for CollectError with skip/skipif. (`#2546
155+
<https://github.com/pytest-dev/pytest/issues/2546>`_)
156+
157+
- Emit warning about ``yield`` tests being deprecated only once per generator.
158+
(`#2562 <https://github.com/pytest-dev/pytest/issues/2562>`_)
159+
160+
- Ensure final collected line doesn't include artifacts of previous write.
161+
(`#2571 <https://github.com/pytest-dev/pytest/issues/2571>`_)
162+
163+
- Fixed all flake8 errors and warnings. (`#2581 <https://github.com/pytest-
164+
dev/pytest/issues/2581>`_)
165+
166+
- Added ``fix-lint`` tox environment to run automatic pep8 fixes on the code.
167+
(`#2582 <https://github.com/pytest-dev/pytest/issues/2582>`_)
168+
169+
- Turn warnings into errors in pytest's own test suite in order to catch
170+
regressions due to deprecations more promptly. (`#2588
171+
<https://github.com/pytest-dev/pytest/issues/2588>`_)
172+
173+
- Show multiple issue links in CHANGELOG entries. (`#2620
174+
<https://github.com/pytest-dev/pytest/issues/2620>`_)
175+
176+
11177
Pytest 3.1.3 (2017-07-03)
12178
=========================
13179

_pytest/_code/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ def repr_excinfo(self, excinfo):
679679
e = e.__cause__
680680
excinfo = ExceptionInfo((type(e), e, e.__traceback__)) if e.__traceback__ else None
681681
descr = 'The above exception was the direct cause of the following exception:'
682-
elif e.__context__ is not None:
682+
elif (e.__context__ is not None and not e.__suppress_context__):
683683
e = e.__context__
684684
excinfo = ExceptionInfo((type(e), e, e.__traceback__)) if e.__traceback__ else None
685685
descr = 'During handling of the above exception, another exception occurred:'

_pytest/cacheprovider.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,31 @@
88
import py
99
import pytest
1010
import json
11+
import os
1112
from os.path import sep as _sep, altsep as _altsep
1213

1314

1415
class Cache(object):
1516
def __init__(self, config):
1617
self.config = config
17-
self._cachedir = config.rootdir.join(".cache")
18+
self._cachedir = Cache.cache_dir_from_config(config)
1819
self.trace = config.trace.root.get("cache")
1920
if config.getvalue("cacheclear"):
2021
self.trace("clearing cachedir")
2122
if self._cachedir.check():
2223
self._cachedir.remove()
2324
self._cachedir.mkdir()
2425

26+
@staticmethod
27+
def cache_dir_from_config(config):
28+
cache_dir = config.getini("cache_dir")
29+
cache_dir = os.path.expanduser(cache_dir)
30+
cache_dir = os.path.expandvars(cache_dir)
31+
if os.path.isabs(cache_dir):
32+
return py.path.local(cache_dir)
33+
else:
34+
return config.rootdir.join(cache_dir)
35+
2536
def makedir(self, name):
2637
""" return a directory path object with the given name. If the
2738
directory does not yet exist, it will be created. You can use it
@@ -94,27 +105,26 @@ def __init__(self, config):
94105
self.config = config
95106
active_keys = 'lf', 'failedfirst'
96107
self.active = any(config.getvalue(key) for key in active_keys)
97-
if self.active:
98-
self.lastfailed = config.cache.get("cache/lastfailed", {})
99-
else:
100-
self.lastfailed = {}
108+
self.lastfailed = config.cache.get("cache/lastfailed", {})
109+
self._previously_failed_count = None
101110

102-
def pytest_report_header(self):
111+
def pytest_report_collectionfinish(self):
103112
if self.active:
104-
if not self.lastfailed:
113+
if not self._previously_failed_count:
105114
mode = "run all (no recorded failures)"
106115
else:
107-
mode = "rerun last %d failures%s" % (
108-
len(self.lastfailed),
109-
" first" if self.config.getvalue("failedfirst") else "")
116+
noun = 'failure' if self._previously_failed_count == 1 else 'failures'
117+
suffix = " first" if self.config.getvalue("failedfirst") else ""
118+
mode = "rerun previous {count} {noun}{suffix}".format(
119+
count=self._previously_failed_count, suffix=suffix, noun=noun
120+
)
110121
return "run-last-failure: %s" % mode
111122

112123
def pytest_runtest_logreport(self, report):
113-
if report.failed and "xfail" not in report.keywords:
124+
if (report.when == 'call' and report.passed) or report.skipped:
125+
self.lastfailed.pop(report.nodeid, None)
126+
elif report.failed:
114127
self.lastfailed[report.nodeid] = True
115-
elif not report.failed:
116-
if report.when == "call":
117-
self.lastfailed.pop(report.nodeid, None)
118128

119129
def pytest_collectreport(self, report):
120130
passed = report.outcome in ('passed', 'skipped')
@@ -136,11 +146,12 @@ def pytest_collection_modifyitems(self, session, config, items):
136146
previously_failed.append(item)
137147
else:
138148
previously_passed.append(item)
139-
if not previously_failed and previously_passed:
149+
self._previously_failed_count = len(previously_failed)
150+
if not previously_failed:
140151
# running a subset of all tests with recorded failures outside
141152
# of the set of tests currently executing
142-
pass
143-
elif self.config.getvalue("lf"):
153+
return
154+
if self.config.getvalue("lf"):
144155
items[:] = previously_failed
145156
config.hook.pytest_deselected(items=previously_passed)
146157
else:
@@ -150,8 +161,9 @@ def pytest_sessionfinish(self, session):
150161
config = self.config
151162
if config.getvalue("cacheshow") or hasattr(config, "slaveinput"):
152163
return
153-
prev_failed = config.cache.get("cache/lastfailed", None) is not None
154-
if (session.testscollected and prev_failed) or self.lastfailed:
164+
165+
saved_lastfailed = config.cache.get("cache/lastfailed", {})
166+
if saved_lastfailed != self.lastfailed:
155167
config.cache.set("cache/lastfailed", self.lastfailed)
156168

157169

@@ -172,6 +184,9 @@ def pytest_addoption(parser):
172184
group.addoption(
173185
'--cache-clear', action='store_true', dest="cacheclear",
174186
help="remove all cache contents at start of test run.")
187+
parser.addini(
188+
"cache_dir", default='.cache',
189+
help="cache directory path.")
175190

176191

177192
def pytest_cmdline_main(config):

_pytest/compat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def isclass(object):
123123
if _PY3:
124124
import codecs
125125
imap = map
126+
izip = zip
126127
STRING_TYPES = bytes, str
127128
UNICODE_TYPES = str,
128129

@@ -158,7 +159,7 @@ def _ascii_escaped(val):
158159
STRING_TYPES = bytes, str, unicode
159160
UNICODE_TYPES = unicode,
160161

161-
from itertools import imap # NOQA
162+
from itertools import imap, izip # NOQA
162163

163164
def _ascii_escaped(val):
164165
"""In py2 bytes and str are the same type, so return if it's a bytes

_pytest/deprecated.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
"""
88
from __future__ import absolute_import, division, print_function
99

10+
11+
class RemovedInPytest4Warning(DeprecationWarning):
12+
"""warning class for features removed in pytest 4.0"""
13+
14+
1015
MAIN_STR_ARGS = 'passing a string to pytest.main() is deprecated, ' \
1116
'pass a list of arguments instead.'
1217

@@ -22,3 +27,13 @@
2227
GETFUNCARGVALUE = "use of getfuncargvalue is deprecated, use getfixturevalue"
2328

2429
RESULT_LOG = '--result-log is deprecated and scheduled for removal in pytest 4.0'
30+
31+
MARK_INFO_ATTRIBUTE = RemovedInPytest4Warning(
32+
"MarkInfo objects are deprecated as they contain the merged marks"
33+
)
34+
35+
MARK_PARAMETERSET_UNPACKING = RemovedInPytest4Warning(
36+
"Applying marks directly to parameters is deprecated,"
37+
" please use pytest.param(..., marks=...) instead.\n"
38+
"For more details, see: https://docs.pytest.org/en/latest/parametrize.html"
39+
)

0 commit comments

Comments
 (0)