Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
2461a43
Merge pull request #4697 from nicoddemus/merge-master-into-features
nicoddemus Jan 31, 2019
fc5d465
Add ability to exclude files matching glob patterns with --ignore-glob
fetzerch Feb 5, 2019
2dc2a19
Add ability to exclude files matching glob patterns in conftest.py
fetzerch Feb 6, 2019
1876a92
Document collect_ignore and collect_ignore_glob in reference
fetzerch Feb 6, 2019
e276bd3
pytest.warns emits a warning on unknown keyword arguments
nicoddemus Feb 5, 2019
4cd268d
Merge pull request #4724 from nicoddemus/pytest-warns-kwargs
RonnyPfannschmidt Feb 7, 2019
64e8185
Merge master into features
blueyed Feb 8, 2019
9c03196
Merge master into features
blueyed Feb 8, 2019
a131cd6
Merge pull request #4749 from blueyed/merge-master-into-features
blueyed Feb 8, 2019
9bcbf55
Add __repr__ for RunResult
blueyed Jan 18, 2019
fc8800c
Merge pull request #4722 from fetzerch/ignore_wildcards
blueyed Feb 8, 2019
ed01dc6
Merge pull request #4652 from blueyed/RunResult-repr
blueyed Feb 9, 2019
7bee359
tox: add generic xdist factor
blueyed Feb 8, 2019
f13935d
Display --help/--version with ArgumentErrors
blueyed Jan 17, 2019
31c9481
Merge pull request #4753 from blueyed/tox-xdist
blueyed Feb 11, 2019
b41632e
Revert "Show deprecation message when running under Python 2.7 and 3.4"
nicoddemus Feb 12, 2019
b759ebd
Add CHANGELOG entry for #4698
nicoddemus Feb 12, 2019
747a8ae
AppVeyor: use xdist for py?? envs, drop py27/py37
blueyed Feb 11, 2019
d03444d
Merge pull request #4651 from blueyed/help-with-argumenterror
nicoddemus Feb 12, 2019
f63fbf8
Merge pull request #4767 from blueyed/appveyor-xdist
nicoddemus Feb 12, 2019
f672b7e
Merge pull request #4773 from nicoddemus/remove-py27-py34-deprecation…
asottile Feb 13, 2019
7b91952
Merge master into features
blueyed Feb 13, 2019
1dbf440
Merge pull request #4785 from blueyed/merge-master-into-features
blueyed Feb 13, 2019
e3824d2
LoggingPlugin: Expose setting log_file_handler
Feb 8, 2019
986dd84
LoggingPlugin: Support to customize log_file from hook (#4752)
nicoddemus Feb 16, 2019
0395996
Merge remote-tracking branch 'upstream/master' into release-4.3.0
nicoddemus Feb 16, 2019
31c869b
Preparing release version 4.3.0
nicoddemus Feb 16, 2019
ff015f6
Fix docs (tox -e regen, plus pre-commit)
blueyed Feb 18, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Allan Feldman
Aly Sivji
Anatoly Bubenkoff
Anders Hovmöller
Andras Mitzki
Andras Tim
Andrea Cimatoribus
Andreas Zeidler
Expand Down Expand Up @@ -51,6 +52,7 @@ Charles Cloud
Charnjit SiNGH (CCSJ)
Chris Lamb
Christian Boelsen
Christian Fetzer
Christian Theunert
Christian Tismer
Christopher Gilling
Expand Down
42 changes: 42 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,48 @@ with advance notice in the **Deprecations** section of releases.

.. towncrier release notes start

pytest 4.3.0 (2019-02-16)
=========================

Deprecations
------------

- `#4724 <https://github.com/pytest-dev/pytest/issues/4724>`_: ``pytest.warns()`` now emits a warning when it receives unknown keyword arguments.

This will be changed into an error in the future.



Features
--------

- `#2753 <https://github.com/pytest-dev/pytest/issues/2753>`_: Usage errors from argparse are mapped to pytest's ``UsageError``.


- `#3711 <https://github.com/pytest-dev/pytest/issues/3711>`_: Add the ``--ignore-glob`` parameter to exclude test-modules with Unix shell-style wildcards.
Add the ``collect_ignore_glob`` for ``conftest.py`` to exclude test-modules with Unix shell-style wildcards.


- `#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.

In the end it was considered to be more
of a nuisance than actual utility and users of those Python versions shouldn't have problems as ``pip`` will not
install pytest 5.0 on those interpreters.


- `#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.



Bug Fixes
---------

- `#4651 <https://github.com/pytest-dev/pytest/issues/4651>`_: ``--help`` and ``--version`` are handled with ``UsageError``.


- `#4782 <https://github.com/pytest-dev/pytest/issues/4782>`_: Fix ``AssertionError`` with collection of broken symlinks with packages.


pytest 4.2.1 (2019-02-12)
=========================

Expand Down
1 change: 0 additions & 1 deletion changelog/4782.bugfix.rst

This file was deleted.

1 change: 1 addition & 0 deletions doc/en/announce/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Release announcements
:maxdepth: 2


release-4.3.0
release-4.2.1
release-4.2.0
release-4.1.1
Expand Down
36 changes: 36 additions & 0 deletions doc/en/announce/release-4.3.0.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
pytest-4.3.0
=======================================

The pytest team is proud to announce the 4.3.0 release!

pytest is a mature Python testing tool with more than a 2000 tests
against itself, passing on many different interpreters and platforms.

This release contains a number of bugs fixes and improvements, so users are encouraged
to take a look at the CHANGELOG:

https://docs.pytest.org/en/latest/changelog.html

For complete documentation, please visit:

https://docs.pytest.org/en/latest/

As usual, you can upgrade from pypi via:

pip install -U pytest

Thanks to all who contributed to this release, among them:

* Andras Mitzki
* Anthony Sottile
* Bruno Oliveira
* Christian Fetzer
* Daniel Hahler
* Grygorii Iermolenko
* R. Alex Matevish
* Ronny Pfannschmidt
* cclauss


Happy testing,
The Pytest Development Team
6 changes: 2 additions & 4 deletions doc/en/example/parametrize.rst
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,8 @@ Running it results in some skips if we don't have all the python interpreters in
.. code-block:: pytest

. $ pytest -rs -q multipython.py
...sss...sssssssss...sss... [100%]
========================= short test summary info ==========================
SKIPPED [15] $REGENDOC_TMPDIR/CWD/multipython.py:30: 'python3.4' not found
12 passed, 15 skipped in 0.12 seconds
........................... [100%]
27 passed in 0.12 seconds

Indirect parametrization of optional implementations/imports
--------------------------------------------------------------------
Expand Down
17 changes: 17 additions & 0 deletions doc/en/example/pythoncollection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ you will see that ``pytest`` only collects test-modules, which do not match the

========================= 5 passed in 0.02 seconds =========================

The ``--ignore-glob`` option allows to ignore test file paths based on Unix shell-style wildcards.
If you want to exclude test-modules that end with ``_01.py``, execute ``pytest`` with ``--ignore-glob='*_01.py'``.

Deselect tests during test collection
-------------------------------------

Expand Down Expand Up @@ -266,3 +269,17 @@ file will be left out:
collected 0 items

======================= no tests ran in 0.12 seconds =======================

It's also possible to ignore files based on Unix shell-style wildcards by adding
patterns to ``collect_ignore_glob``.

The following example ``conftest.py`` ignores the file ``setup.py`` and in
addition all files that end with ``*_py2.py`` when executed with a Python 3
interpreter::

# content of conftest.py
import sys

collect_ignore = ["setup.py"]
if sys.version_info[0] > 2:
collect_ignore_glob = ["*_py2.py"]
3 changes: 3 additions & 0 deletions doc/en/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ option names are:
* ``log_file_format``
* ``log_file_date_format``

You can call ``set_log_path()`` to customize the log_file path dynamically. This functionality
is considered **experimental**.

.. _log_release_notes:

Release notes
Expand Down
27 changes: 27 additions & 0 deletions doc/en/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,33 @@ Special Variables
pytest treats some global variables in a special manner when defined in a test module.


collect_ignore
~~~~~~~~~~~~~~

**Tutorial**: :ref:`customizing-test-collection`

Can be declared in *conftest.py files* to exclude test directories or modules.
Needs to be ``list[str]``.

.. code-block:: python

collect_ignore = ["setup.py"]


collect_ignore_glob
~~~~~~~~~~~~~~~~~~~

**Tutorial**: :ref:`customizing-test-collection`

Can be declared in *conftest.py files* to exclude test directories or modules
with Unix shell-style wildcards. Needs to be ``list[str]`` where ``str`` can
contain glob patterns.

.. code-block:: python

collect_ignore_glob = ["*_ignore.py"]


pytest_plugins
~~~~~~~~~~~~~~

Expand Down
46 changes: 38 additions & 8 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,27 @@ def get_terminal_writer(self):
return self.pluginmanager.get_plugin("terminalreporter")._tw

def pytest_cmdline_parse(self, pluginmanager, args):
# REF1 assert self == pluginmanager.config, (self, pluginmanager.config)
self.parse(args)
try:
self.parse(args)
except UsageError:

# Handle --version and --help here in a minimal fashion.
# This gets done via helpconfig normally, but its
# pytest_cmdline_main is not called in case of errors.
if getattr(self.option, "version", False) or "--version" in args:
from _pytest.helpconfig import showversion

showversion(self)
elif (
getattr(self.option, "help", False) or "--help" in args or "-h" in args
):
self._parser._getparser().print_help()
sys.stdout.write(
"\nNOTE: displaying only minimal help due to UsageError.\n\n"
)

raise

return self

def notify_exception(self, excinfo, option=None):
Expand Down Expand Up @@ -763,21 +782,32 @@ def _mark_plugins_for_rewrite(self, hook):
for name in _iter_rewritable_modules(package_files):
hook.mark_rewrite(name)

def _validate_args(self, args):
def _validate_args(self, args, via):
"""Validate known args."""
self._parser.parse_known_and_unknown_args(
args, namespace=copy.copy(self.option)
)
self._parser._config_source_hint = via
try:
self._parser.parse_known_and_unknown_args(
args, namespace=copy.copy(self.option)
)
finally:
del self._parser._config_source_hint

return args

def _preparse(self, args, addopts=True):
if addopts:
env_addopts = os.environ.get("PYTEST_ADDOPTS", "")
if len(env_addopts):
args[:] = self._validate_args(shlex.split(env_addopts)) + args
args[:] = (
self._validate_args(shlex.split(env_addopts), "via PYTEST_ADDOPTS")
+ args
)
self._initini(args)
if addopts:
args[:] = self._validate_args(self.getini("addopts")) + args
args[:] = (
self._validate_args(self.getini("addopts"), "via addopts config") + args
)

self._checkversion()
self._consider_importhook(args)
self.pluginmanager.consider_preparse(args)
Expand Down
19 changes: 8 additions & 11 deletions src/_pytest/config/argparsing.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import argparse
import sys as _sys
import warnings
from gettext import gettext as _

import py
import six

from ..main import EXIT_USAGEERROR
from _pytest.config.exceptions import UsageError

FILE_OR_DIR = "file_or_dir"

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

def error(self, message):
"""error(message: string)

Prints a usage message incorporating the message to stderr and
exits.
Overrides the method in parent class to change exit code"""
self.print_usage(_sys.stderr)
args = {"prog": self.prog, "message": message}
self.exit(EXIT_USAGEERROR, _("%(prog)s: error: %(message)s\n") % args)
"""Transform argparse error message into UsageError."""
msg = "%s: error: %s" % (self.prog, message)

if hasattr(self._parser, "_config_source_hint"):
msg = "%s (%s)" % (msg, self._parser._config_source_hint)

raise UsageError(self.format_usage() + msg)

def parse_args(self, args=None, namespace=None):
"""allow splitting of positional arguments"""
Expand Down
7 changes: 7 additions & 0 deletions src/_pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from _pytest.warning_types import PytestDeprecationWarning
from _pytest.warning_types import RemovedInPytest4Warning
from _pytest.warning_types import UnformattedWarning


YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored"
Expand Down Expand Up @@ -87,3 +88,9 @@
"pytest_logwarning is deprecated, no longer being called, and will be removed soon\n"
"please use pytest_warning_captured instead"
)

PYTEST_WARNS_UNKNOWN_KWARGS = UnformattedWarning(
PytestDeprecationWarning,
"pytest.warns() got unexpected keyword arguments: {args!r}.\n"
"This will be an error in future versions.",
)
20 changes: 12 additions & 8 deletions src/_pytest/helpconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,20 @@ def unset_tracing():
config.add_cleanup(unset_tracing)


def showversion(config):
p = py.path.local(pytest.__file__)
sys.stderr.write(
"This is pytest version %s, imported from %s\n" % (pytest.__version__, p)
)
plugininfo = getpluginversioninfo(config)
if plugininfo:
for line in plugininfo:
sys.stderr.write(line + "\n")


def pytest_cmdline_main(config):
if config.option.version:
p = py.path.local(pytest.__file__)
sys.stderr.write(
"This is pytest version %s, imported from %s\n" % (pytest.__version__, p)
)
plugininfo = getpluginversioninfo(config)
if plugininfo:
for line in plugininfo:
sys.stderr.write(line + "\n")
showversion(config)
return 0
elif config.option.help:
config._do_configure()
Expand Down
Loading