Skip to content

Commit b9561e2

Browse files
authored
Merge pull request #4808 from nicoddemus/merge-master-into-features
Merge master into features
2 parents 986dd84 + f0a9f90 commit b9561e2

22 files changed

+188
-71
lines changed

.travis.yml

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
sudo: false
21
language: python
32
dist: xenial
43
stages:
@@ -26,22 +25,20 @@ env:
2625
matrix:
2726
allow_failures:
2827
- python: '3.8-dev'
29-
env: TOXENV=py38
28+
env: TOXENV=py38-xdist
3029

3130
jobs:
3231
include:
3332
# Coverage tracking is slow with pypy, skip it.
3433
- env: TOXENV=pypy PYTEST_NO_COVERAGE=1
3534
python: 'pypy-5.4'
3635
dist: trusty
37-
- env: TOXENV=py34
36+
- env: TOXENV=py34-xdist
3837
python: '3.4'
39-
- env: TOXENV=py35
38+
- env: TOXENV=py35-xdist
4039
python: '3.5'
41-
- env: TOXENV=py36
40+
- env: TOXENV=py36-xdist
4241
python: '3.6'
43-
- env: TOXENV=py38
44-
python: '3.8-dev'
4542
- env: TOXENV=py37
4643
- &test-macos
4744
language: generic
@@ -50,15 +47,20 @@ jobs:
5047
sudo: required
5148
install:
5249
- python -m pip install --pre tox
53-
env: TOXENV=py27
50+
env: TOXENV=py27-xdist
5451
- <<: *test-macos
55-
env: TOXENV=py37
52+
env: TOXENV=py37-xdist
5653
before_install:
5754
- brew update
5855
- brew upgrade python
5956
- brew unlink python
6057
- brew link python
6158

59+
# Jobs only run via Travis cron jobs (currently daily).
60+
- env: TOXENV=py38-xdist
61+
python: '3.8-dev'
62+
if: type = cron
63+
6264
- stage: baseline
6365
env: TOXENV=py27-pexpect,py27-trial,py27-numpy
6466
- env: TOXENV=py37-xdist

CHANGELOG.rst

+42
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,48 @@ with advance notice in the **Deprecations** section of releases.
1818
1919
.. towncrier release notes start
2020
21+
pytest 4.3.0 (2019-02-16)
22+
=========================
23+
24+
Deprecations
25+
------------
26+
27+
- `#4724 <https://github.com/pytest-dev/pytest/issues/4724>`_: ``pytest.warns()`` now emits a warning when it receives unknown keyword arguments.
28+
29+
This will be changed into an error in the future.
30+
31+
32+
33+
Features
34+
--------
35+
36+
- `#2753 <https://github.com/pytest-dev/pytest/issues/2753>`_: Usage errors from argparse are mapped to pytest's ``UsageError``.
37+
38+
39+
- `#3711 <https://github.com/pytest-dev/pytest/issues/3711>`_: Add the ``--ignore-glob`` parameter to exclude test-modules with Unix shell-style wildcards.
40+
Add the ``collect_ignore_glob`` for ``conftest.py`` to exclude test-modules with Unix shell-style wildcards.
41+
42+
43+
- `#4698 <https://github.com/pytest-dev/pytest/issues/4698>`_: The warning about Python 2.7 and 3.4 not being supported in pytest 5.0 has been removed.
44+
45+
In the end it was considered to be more
46+
of a nuisance than actual utility and users of those Python versions shouldn't have problems as ``pip`` will not
47+
install pytest 5.0 on those interpreters.
48+
49+
50+
- `#4707 <https://github.com/pytest-dev/pytest/issues/4707>`_: With the help of new ``set_log_path()`` method there is a way to set ``log_file`` paths from hooks.
51+
52+
53+
54+
Bug Fixes
55+
---------
56+
57+
- `#4651 <https://github.com/pytest-dev/pytest/issues/4651>`_: ``--help`` and ``--version`` are handled with ``UsageError``.
58+
59+
60+
- `#4782 <https://github.com/pytest-dev/pytest/issues/4782>`_: Fix ``AssertionError`` with collection of broken symlinks with packages.
61+
62+
2163
pytest 4.2.1 (2019-02-12)
2264
=========================
2365

changelog/2753.feature.rst

-1
This file was deleted.

changelog/3711.feature.rst

-2
This file was deleted.

changelog/4651.bugfix.rst

-1
This file was deleted.

changelog/4698.feature.rst

-5
This file was deleted.

changelog/4707.feature.rst

-1
This file was deleted.

changelog/4724.deprecation.rst

-3
This file was deleted.

doc/en/announce/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Release announcements
66
:maxdepth: 2
77

88

9+
release-4.3.0
910
release-4.2.1
1011
release-4.2.0
1112
release-4.1.1

doc/en/announce/release-4.3.0.rst

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
pytest-4.3.0
2+
=======================================
3+
4+
The pytest team is proud to announce the 4.3.0 release!
5+
6+
pytest is a mature Python testing tool with more than a 2000 tests
7+
against itself, passing on many different interpreters and platforms.
8+
9+
This release contains a number of bugs fixes and improvements, so users are encouraged
10+
to take a look at the CHANGELOG:
11+
12+
https://docs.pytest.org/en/latest/changelog.html
13+
14+
For complete documentation, please visit:
15+
16+
https://docs.pytest.org/en/latest/
17+
18+
As usual, you can upgrade from pypi via:
19+
20+
pip install -U pytest
21+
22+
Thanks to all who contributed to this release, among them:
23+
24+
* Andras Mitzki
25+
* Anthony Sottile
26+
* Bruno Oliveira
27+
* Christian Fetzer
28+
* Daniel Hahler
29+
* Grygorii Iermolenko
30+
* R. Alex Matevish
31+
* Ronny Pfannschmidt
32+
* cclauss
33+
34+
35+
Happy testing,
36+
The Pytest Development Team

doc/en/assert.rst

+18-28
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,30 @@ and if you need to have access to the actual exception info you may use::
8888
the actual exception raised. The main attributes of interest are
8989
``.type``, ``.value`` and ``.traceback``.
9090

91-
.. versionchanged:: 3.0
91+
You can pass a ``match`` keyword parameter to the context-manager to test
92+
that a regular expression matches on the string representation of an exception
93+
(similar to the ``TestCase.assertRaisesRegexp`` method from ``unittest``)::
9294

93-
In the context manager form you may use the keyword argument
94-
``message`` to specify a custom failure message::
95+
import pytest
9596

96-
>>> with raises(ZeroDivisionError, message="Expecting ZeroDivisionError"):
97-
... pass
98-
... Failed: Expecting ZeroDivisionError
97+
def myfunc():
98+
raise ValueError("Exception 123 raised")
9999

100-
If you want to write test code that works on Python 2.4 as well,
101-
you may also use two other ways to test for an expected exception::
100+
def test_match():
101+
with pytest.raises(ValueError, match=r'.* 123 .*'):
102+
myfunc()
103+
104+
The regexp parameter of the ``match`` method is matched with the ``re.search``
105+
function, so in the above example ``match='123'`` would have worked as
106+
well.
107+
108+
There's an alternate form of the ``pytest.raises`` function where you pass
109+
a function that will be executed with the given ``*args`` and ``**kwargs`` and
110+
assert that the given exception is raised::
102111

103112
pytest.raises(ExpectedException, func, *args, **kwargs)
104113

105-
which will execute the specified function with args and kwargs and
106-
assert that the given ``ExpectedException`` is raised. The reporter will
107-
provide you with helpful output in case of failures such as *no
114+
The reporter will provide you with helpful output in case of failures such as *no
108115
exception* or *wrong exception*.
109116

110117
Note that it is also possible to specify a "raises" argument to
@@ -121,23 +128,6 @@ exceptions your own code is deliberately raising, whereas using
121128
like documenting unfixed bugs (where the test describes what "should" happen)
122129
or bugs in dependencies.
123130

124-
Also, the context manager form accepts a ``match`` keyword parameter to test
125-
that a regular expression matches on the string representation of an exception
126-
(like the ``TestCase.assertRaisesRegexp`` method from ``unittest``)::
127-
128-
import pytest
129-
130-
def myfunc():
131-
raise ValueError("Exception 123 raised")
132-
133-
def test_match():
134-
with pytest.raises(ValueError, match=r'.* 123 .*'):
135-
myfunc()
136-
137-
The regexp parameter of the ``match`` method is matched with the ``re.search``
138-
function. So in the above example ``match='123'`` would have worked as
139-
well.
140-
141131

142132
.. _`assertwarns`:
143133

doc/en/example/parametrize.rst

+2-4
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,8 @@ Running it results in some skips if we don't have all the python interpreters in
436436
.. code-block:: pytest
437437
438438
. $ pytest -rs -q multipython.py
439-
...sss...sssssssss...sss... [100%]
440-
========================= short test summary info ==========================
441-
SKIPPED [15] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.4' not found
442-
12 passed, 15 skipped in 0.12 seconds
439+
........................... [100%]
440+
27 passed in 0.12 seconds
443441
444442
Indirect parametrization of optional implementations/imports
445443
--------------------------------------------------------------------

doc/en/talks.rst

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Talks and blog postings
2525

2626
- pytest: recommendations, basic packages for testing in Python and Django, Andreu Vallbona, PyconES 2017 (`slides in english <http://talks.apsl.io/testing-pycones-2017/>`_, `video in spanish <https://www.youtube.com/watch?v=K20GeR-lXDk>`_)
2727

28+
- `pytest advanced, Andrew Svetlov (Russian, PyCon Russia, 2016)
29+
<https://www.youtube.com/watch?v=7KgihdKTWY4>`_.
30+
2831
- `Pythonic testing, Igor Starikov (Russian, PyNsk, November 2016)
2932
<https://www.youtube.com/watch?v=_92nfdd5nK8>`_.
3033

src/_pytest/main.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,12 @@ def _collect(self, arg):
618618
yield y
619619

620620
def _collectfile(self, path, handle_dupes=True):
621-
assert path.isfile()
621+
assert path.isfile(), "%r is not a file (isdir=%r, exists=%r, islink=%r)" % (
622+
path,
623+
path.isdir(),
624+
path.exists(),
625+
path.islink(),
626+
)
622627
ihook = self.gethookproxy(path)
623628
if not self.isinitpath(path):
624629
if ihook.pytest_ignore_collect(path=path, config=self.config):

src/_pytest/nodes.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ def warn(self, warning):
113113
114114
:raise ValueError: if ``warning`` instance is not a subclass of PytestWarning.
115115
116-
Example usage::
116+
Example usage:
117117
118118
.. code-block:: python
119119
120120
node.warn(PytestWarning("some message"))
121+
121122
"""
122123
from _pytest.warning_types import PytestWarning
123124

src/_pytest/python.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,12 @@ def gethookproxy(self, fspath):
599599
return proxy
600600

601601
def _collectfile(self, path, handle_dupes=True):
602-
assert path.isfile()
602+
assert path.isfile(), "%r is not a file (isdir=%r, exists=%r, islink=%r)" % (
603+
path,
604+
path.isdir(),
605+
path.exists(),
606+
path.islink(),
607+
)
603608
ihook = self.gethookproxy(path)
604609
if not self.isinitpath(path):
605610
if ihook.pytest_ignore_collect(path=path, config=self.config):
@@ -632,7 +637,8 @@ def collect(self):
632637
pkg_prefixes = set()
633638
for path in this_path.visit(rec=self._recurse, bf=True, sort=True):
634639
# We will visit our own __init__.py file, in which case we skip it.
635-
if path.isfile():
640+
is_file = path.isfile()
641+
if is_file:
636642
if path.basename == "__init__.py" and path.dirpath() == this_path:
637643
continue
638644

@@ -643,12 +649,14 @@ def collect(self):
643649
):
644650
continue
645651

646-
if path.isdir():
647-
if path.join("__init__.py").check(file=1):
648-
pkg_prefixes.add(path)
649-
else:
652+
if is_file:
650653
for x in self._collectfile(path):
651654
yield x
655+
elif not path.isdir():
656+
# Broken symlink or invalid/missing file.
657+
continue
658+
elif path.join("__init__.py").check(file=1):
659+
pkg_prefixes.add(path)
652660

653661

654662
def _get_xunit_setup_teardown(holder, attr_name, param_obj=None):

src/_pytest/terminal.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ def hasopt(self, char):
280280

281281
def write_fspath_result(self, nodeid, res, **markup):
282282
fspath = self.config.rootdir.join(nodeid.split("::")[0])
283-
if fspath != self.currentfspath:
283+
# NOTE: explicitly check for None to work around py bug, and for less
284+
# overhead in general (https://github.com/pytest-dev/py/pull/207).
285+
if self.currentfspath is None or fspath != self.currentfspath:
284286
if self.currentfspath is not None and self._show_progress_info:
285287
self._write_progress_information_filling_space()
286288
self.currentfspath = fspath

src/_pytest/tmpdir.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class TempPathFactory(object):
3131
# using os.path.abspath() to get absolute path instead of resolve() as it
3232
# does not work the same in all platforms (see #4427)
3333
# Path.absolute() exists, but it is not public (see https://bugs.python.org/issue25012)
34-
convert=attr.converters.optional(
34+
converter=attr.converters.optional(
3535
lambda p: Path(os.path.abspath(six.text_type(p)))
3636
)
3737
)

testing/code/test_source.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,6 @@ def test_oneline_and_comment():
560560
assert str(source) == "raise ValueError"
561561

562562

563-
@pytest.mark.xfail(hasattr(sys, "pypy_version_info"), reason="does not work on pypy")
564563
def test_comments():
565564
source = '''def test():
566565
"comment 1"
@@ -576,9 +575,15 @@ def test_comments():
576575
'''
577576
for line in range(2, 6):
578577
assert str(getstatement(line, source)) == " x = 1"
579-
for line in range(6, 10):
578+
if sys.version_info >= (3, 8) or hasattr(sys, "pypy_version_info"):
579+
tqs_start = 8
580+
else:
581+
tqs_start = 10
582+
assert str(getstatement(10, source)) == '"""'
583+
for line in range(6, tqs_start):
580584
assert str(getstatement(line, source)) == " assert False"
581-
assert str(getstatement(10, source)) == '"""'
585+
for line in range(tqs_start, 10):
586+
assert str(getstatement(line, source)) == '"""\ncomment 4\n"""'
582587

583588

584589
def test_comment_in_statement():

0 commit comments

Comments
 (0)