Skip to content

Commit f0a9f90

Browse files
authored
Merge pull request #4805 from nicoddemus/release-4.3.0
Release 4.3.0
2 parents eeac28f + ff015f6 commit f0a9f90

26 files changed

+449
-90
lines changed

AUTHORS

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Allan Feldman
1616
Aly Sivji
1717
Anatoly Bubenkoff
1818
Anders Hovmöller
19+
Andras Mitzki
1920
Andras Tim
2021
Andrea Cimatoribus
2122
Andreas Zeidler
@@ -51,6 +52,7 @@ Charles Cloud
5152
Charnjit SiNGH (CCSJ)
5253
Chris Lamb
5354
Christian Boelsen
55+
Christian Fetzer
5456
Christian Theunert
5557
Christian Tismer
5658
Christopher Gilling

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/4782.bugfix.rst

-1
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/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/example/pythoncollection.rst

+17
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ you will see that ``pytest`` only collects test-modules, which do not match the
4141
4242
========================= 5 passed in 0.02 seconds =========================
4343
44+
The ``--ignore-glob`` option allows to ignore test file paths based on Unix shell-style wildcards.
45+
If you want to exclude test-modules that end with ``_01.py``, execute ``pytest`` with ``--ignore-glob='*_01.py'``.
46+
4447
Deselect tests during test collection
4548
-------------------------------------
4649

@@ -266,3 +269,17 @@ file will be left out:
266269
collected 0 items
267270
268271
======================= no tests ran in 0.12 seconds =======================
272+
273+
It's also possible to ignore files based on Unix shell-style wildcards by adding
274+
patterns to ``collect_ignore_glob``.
275+
276+
The following example ``conftest.py`` ignores the file ``setup.py`` and in
277+
addition all files that end with ``*_py2.py`` when executed with a Python 3
278+
interpreter::
279+
280+
# content of conftest.py
281+
import sys
282+
283+
collect_ignore = ["setup.py"]
284+
if sys.version_info[0] > 2:
285+
collect_ignore_glob = ["*_py2.py"]

doc/en/logging.rst

+3
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,9 @@ option names are:
198198
* ``log_file_format``
199199
* ``log_file_date_format``
200200

201+
You can call ``set_log_path()`` to customize the log_file path dynamically. This functionality
202+
is considered **experimental**.
203+
201204
.. _log_release_notes:
202205

203206
Release notes

doc/en/reference.rst

+27
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,33 @@ Special Variables
797797
pytest treats some global variables in a special manner when defined in a test module.
798798

799799

800+
collect_ignore
801+
~~~~~~~~~~~~~~
802+
803+
**Tutorial**: :ref:`customizing-test-collection`
804+
805+
Can be declared in *conftest.py files* to exclude test directories or modules.
806+
Needs to be ``list[str]``.
807+
808+
.. code-block:: python
809+
810+
collect_ignore = ["setup.py"]
811+
812+
813+
collect_ignore_glob
814+
~~~~~~~~~~~~~~~~~~~
815+
816+
**Tutorial**: :ref:`customizing-test-collection`
817+
818+
Can be declared in *conftest.py files* to exclude test directories or modules
819+
with Unix shell-style wildcards. Needs to be ``list[str]`` where ``str`` can
820+
contain glob patterns.
821+
822+
.. code-block:: python
823+
824+
collect_ignore_glob = ["*_ignore.py"]
825+
826+
800827
pytest_plugins
801828
~~~~~~~~~~~~~~
802829

src/_pytest/config/__init__.py

+38-8
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,27 @@ def get_terminal_writer(self):
651651
return self.pluginmanager.get_plugin("terminalreporter")._tw
652652

653653
def pytest_cmdline_parse(self, pluginmanager, args):
654-
# REF1 assert self == pluginmanager.config, (self, pluginmanager.config)
655-
self.parse(args)
654+
try:
655+
self.parse(args)
656+
except UsageError:
657+
658+
# Handle --version and --help here in a minimal fashion.
659+
# This gets done via helpconfig normally, but its
660+
# pytest_cmdline_main is not called in case of errors.
661+
if getattr(self.option, "version", False) or "--version" in args:
662+
from _pytest.helpconfig import showversion
663+
664+
showversion(self)
665+
elif (
666+
getattr(self.option, "help", False) or "--help" in args or "-h" in args
667+
):
668+
self._parser._getparser().print_help()
669+
sys.stdout.write(
670+
"\nNOTE: displaying only minimal help due to UsageError.\n\n"
671+
)
672+
673+
raise
674+
656675
return self
657676

658677
def notify_exception(self, excinfo, option=None):
@@ -763,21 +782,32 @@ def _mark_plugins_for_rewrite(self, hook):
763782
for name in _iter_rewritable_modules(package_files):
764783
hook.mark_rewrite(name)
765784

766-
def _validate_args(self, args):
785+
def _validate_args(self, args, via):
767786
"""Validate known args."""
768-
self._parser.parse_known_and_unknown_args(
769-
args, namespace=copy.copy(self.option)
770-
)
787+
self._parser._config_source_hint = via
788+
try:
789+
self._parser.parse_known_and_unknown_args(
790+
args, namespace=copy.copy(self.option)
791+
)
792+
finally:
793+
del self._parser._config_source_hint
794+
771795
return args
772796

773797
def _preparse(self, args, addopts=True):
774798
if addopts:
775799
env_addopts = os.environ.get("PYTEST_ADDOPTS", "")
776800
if len(env_addopts):
777-
args[:] = self._validate_args(shlex.split(env_addopts)) + args
801+
args[:] = (
802+
self._validate_args(shlex.split(env_addopts), "via PYTEST_ADDOPTS")
803+
+ args
804+
)
778805
self._initini(args)
779806
if addopts:
780-
args[:] = self._validate_args(self.getini("addopts")) + args
807+
args[:] = (
808+
self._validate_args(self.getini("addopts"), "via addopts config") + args
809+
)
810+
781811
self._checkversion()
782812
self._consider_importhook(args)
783813
self.pluginmanager.consider_preparse(args)

src/_pytest/config/argparsing.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import argparse
2-
import sys as _sys
32
import warnings
4-
from gettext import gettext as _
53

64
import py
75
import six
86

9-
from ..main import EXIT_USAGEERROR
7+
from _pytest.config.exceptions import UsageError
108

119
FILE_OR_DIR = "file_or_dir"
1210

@@ -337,14 +335,13 @@ def __init__(self, parser, extra_info=None, prog=None):
337335
self.extra_info = extra_info
338336

339337
def error(self, message):
340-
"""error(message: string)
341-
342-
Prints a usage message incorporating the message to stderr and
343-
exits.
344-
Overrides the method in parent class to change exit code"""
345-
self.print_usage(_sys.stderr)
346-
args = {"prog": self.prog, "message": message}
347-
self.exit(EXIT_USAGEERROR, _("%(prog)s: error: %(message)s\n") % args)
338+
"""Transform argparse error message into UsageError."""
339+
msg = "%s: error: %s" % (self.prog, message)
340+
341+
if hasattr(self._parser, "_config_source_hint"):
342+
msg = "%s (%s)" % (msg, self._parser._config_source_hint)
343+
344+
raise UsageError(self.format_usage() + msg)
348345

349346
def parse_args(self, args=None, namespace=None):
350347
"""allow splitting of positional arguments"""

src/_pytest/deprecated.py

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from _pytest.warning_types import PytestDeprecationWarning
1616
from _pytest.warning_types import RemovedInPytest4Warning
17+
from _pytest.warning_types import UnformattedWarning
1718

1819

1920
YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored"
@@ -87,3 +88,9 @@
8788
"pytest_logwarning is deprecated, no longer being called, and will be removed soon\n"
8889
"please use pytest_warning_captured instead"
8990
)
91+
92+
PYTEST_WARNS_UNKNOWN_KWARGS = UnformattedWarning(
93+
PytestDeprecationWarning,
94+
"pytest.warns() got unexpected keyword arguments: {args!r}.\n"
95+
"This will be an error in future versions.",
96+
)

src/_pytest/helpconfig.py

+12-8
Original file line numberDiff line numberDiff line change
@@ -118,16 +118,20 @@ def unset_tracing():
118118
config.add_cleanup(unset_tracing)
119119

120120

121+
def showversion(config):
122+
p = py.path.local(pytest.__file__)
123+
sys.stderr.write(
124+
"This is pytest version %s, imported from %s\n" % (pytest.__version__, p)
125+
)
126+
plugininfo = getpluginversioninfo(config)
127+
if plugininfo:
128+
for line in plugininfo:
129+
sys.stderr.write(line + "\n")
130+
131+
121132
def pytest_cmdline_main(config):
122133
if config.option.version:
123-
p = py.path.local(pytest.__file__)
124-
sys.stderr.write(
125-
"This is pytest version %s, imported from %s\n" % (pytest.__version__, p)
126-
)
127-
plugininfo = getpluginversioninfo(config)
128-
if plugininfo:
129-
for line in plugininfo:
130-
sys.stderr.write(line + "\n")
134+
showversion(config)
131135
return 0
132136
elif config.option.help:
133137
config._do_configure()

0 commit comments

Comments
 (0)