.. _`changelog`:
=========
Changelog
=========
Versions follow `Semantic Versioning `_ (``..``).
Backward incompatible (breaking) changes will only be introduced in major versions
with advance notice in the **Deprecations** section of releases.
..
You should *NOT* be adding new change log entries to this file, this
file is managed by towncrier. You *may* edit previous change logs to
fix problems like typo corrections or such.
To add a new change log entry, please see
https://pip.pypa.io/en/latest/development/contributing/#news-entries
we named the news folder changelog
.. only:: changelog_towncrier_draft
.. The 'changelog_towncrier_draft' tag is included by our 'tox -e docs',
but not on readthedocs.
.. include:: _changelog_towncrier_draft.rst
.. towncrier release notes start
pytest 7.2.1 (2023-01-13)
=========================
Bug Fixes
---------
- `#10452 `_: Fix 'importlib.abc.TraversableResources' deprecation warning in Python 3.12.
- `#10457 `_: If a test is skipped from inside a fixture, the test summary now shows the test location instead of the fixture location.
- `#10506 `_: Fix bug where sometimes pytest would use the file system root directory as :ref:`rootdir ` on Windows.
- `#10607 `_: Fix a race condition when creating junitxml reports, which could occur when multiple instances of pytest execute in parallel.
- `#10641 `_: Fix a race condition when creating or updating the stepwise plugin's cache, which could occur when multiple xdist worker nodes try to simultaneously update the stepwise plugin's cache.
pytest 7.2.0 (2022-10-23)
=========================
Deprecations
------------
- `#10012 `_: Update :class:`pytest.PytestUnhandledCoroutineWarning` to a deprecation; it will raise an error in pytest 8.
- `#10396 `_: pytest no longer depends on the ``py`` library. ``pytest`` provides a vendored copy of ``py.error`` and ``py.path`` modules but will use the ``py`` library if it is installed. If you need other ``py.*`` modules, continue to install the deprecated ``py`` library separately, otherwise it can usually be removed as a dependency.
- `#4562 `_: Deprecate configuring hook specs/impls using attributes/marks.
Instead use :py:func:`pytest.hookimpl` and :py:func:`pytest.hookspec`.
For more details, see the :ref:`docs `.
- `#9886 `_: The functionality for running tests written for ``nose`` has been officially deprecated.
This includes:
* Plain ``setup`` and ``teardown`` functions and methods: this might catch users by surprise, as ``setup()`` and ``teardown()`` are not pytest idioms, but part of the ``nose`` support.
* Setup/teardown using the `@with_setup `_ decorator.
For more details, consult the :ref:`deprecation docs `.
.. _`with-setup-nose`: https://nose.readthedocs.io/en/latest/testing_tools.html?highlight=with_setup#nose.tools.with_setup
- `#7337 `_: A deprecation warning is now emitted if a test function returns something other than `None`. This prevents a common mistake among beginners that expect that returning a `bool` (for example `return foo(a, b) == result`) would cause a test to pass or fail, instead of using `assert`. The plan is to make returning non-`None` from tests an error in the future.
Features
--------
- `#9897 `_: Added shell-style wildcard support to ``testpaths``.
Improvements
------------
- `#10218 `_: ``@pytest.mark.parametrize()`` (and similar functions) now accepts any ``Sequence[str]`` for the argument names,
instead of just ``list[str]`` and ``tuple[str, ...]``.
(Note that ``str``, which is itself a ``Sequence[str]``, is still treated as a
comma-delimited name list, as before).
- `#10381 `_: The ``--no-showlocals`` flag has been added. This can be passed directly to tests to override ``--showlocals`` declared through ``addopts``.
- `#3426 `_: Assertion failures with strings in NFC and NFD forms that normalize to the same string now have a dedicated error message detailing the issue, and their utf-8 representation is expressed instead.
- `#8508 `_: Introduce multiline display for warning matching via :py:func:`pytest.warns` and
enhance match comparison for :py:func:`_pytest._code.ExceptionInfo.match` as returned by :py:func:`pytest.raises`.
- `#8646 `_: Improve :py:func:`pytest.raises`. Previously passing an empty tuple would give a confusing
error. We now raise immediately with a more helpful message.
- `#9741 `_: On Python 3.11, use the standard library's :mod:`tomllib` to parse TOML.
:mod:`tomli` is no longer a dependency on Python 3.11.
- `#9742 `_: Display assertion message without escaped newline characters with ``-vv``.
- `#9823 `_: Improved error message that is shown when no collector is found for a given file.
- `#9873 `_: Some coloring has been added to the short test summary.
- `#9883 `_: Normalize the help description of all command-line options.
- `#9920 `_: Display full crash messages in ``short test summary info``, when running in a CI environment.
- `#9987 `_: Added support for hidden configuration file by allowing ``.pytest.ini`` as an alternative to ``pytest.ini``.
Bug Fixes
---------
- `#10150 `_: :data:`sys.stdin` now contains all expected methods of a file-like object when capture is enabled.
- `#10382 `_: Do not break into pdb when ``raise unittest.SkipTest()`` appears top-level in a file.
- `#7792 `_: Marks are now inherited according to the full MRO in test classes. Previously, if a test class inherited from two or more classes, only marks from the first super-class would apply.
When inheriting marks from super-classes, marks from the sub-classes are now ordered before marks from the super-classes, in MRO order. Previously it was the reverse.
When inheriting marks from super-classes, the `pytestmark` attribute of the sub-class now only contains the marks directly applied to it. Previously, it also contained marks from its super-classes. Please note that this attribute should not normally be accessed directly; use :func:`pytest.Node.iter_markers` instead.
- `#9159 `_: Showing inner exceptions by forcing native display in ``ExceptionGroups`` even when using display options other than ``--tb=native``. A temporary step before full implementation of pytest-native display for inner exceptions in ``ExceptionGroups``.
- `#9877 `_: Ensure ``caplog.get_records(when)`` returns current/correct data after invoking ``caplog.clear()``.
Improved Documentation
----------------------
- `#10344 `_: Update information on writing plugins to use ``pyproject.toml`` instead of ``setup.py``.
- `#9248 `_: The documentation is now built using Sphinx 5.x (up from 3.x previously).
- `#9291 `_: Update documentation on how :func:`pytest.warns` affects :class:`DeprecationWarning`.
Trivial/Internal Changes
------------------------
- `#10313 `_: Made ``_pytest.doctest.DoctestItem`` export ``pytest.DoctestItem`` for
type check and runtime purposes. Made `_pytest.doctest` use internal APIs
to avoid circular imports.
- `#9906 `_: Made ``_pytest.compat`` re-export ``importlib_metadata`` in the eyes of type checkers.
- `#9910 `_: Fix default encoding warning (``EncodingWarning``) in ``cacheprovider``
- `#9984 `_: Improve the error message when we attempt to access a fixture that has been
torn down.
Add an additional sentence to the docstring explaining when it's not a good
idea to call ``getfixturevalue``.
pytest 7.1.3 (2022-08-31)
=========================
Bug Fixes
---------
- `#10060 `_: When running with ``--pdb``, ``TestCase.tearDown`` is no longer called for tests when the *class* has been skipped via ``unittest.skip`` or ``pytest.mark.skip``.
- `#10190 `_: Invalid XML characters in setup or teardown error messages are now properly escaped for JUnit XML reports.
- `#10230 `_: Ignore ``.py`` files created by ``pyproject.toml``-based editable builds introduced in `pip 21.3 `__.
- `#3396 `_: Doctests now respect the ``--import-mode`` flag.
- `#9514 `_: Type-annotate ``FixtureRequest.param`` as ``Any`` as a stop gap measure until :issue:`8073` is fixed.
- `#9791 `_: Fixed a path handling code in ``rewrite.py`` that seems to work fine, but was incorrect and fails in some systems.
- `#9917 `_: Fixed string representation for :func:`pytest.approx` when used to compare tuples.
Improved Documentation
----------------------
- `#9937 `_: Explicit note that :fixture:`tmpdir` fixture is discouraged in favour of :fixture:`tmp_path`.
Trivial/Internal Changes
------------------------
- `#10114 `_: Replace `atomicwrites `__ dependency on windows with `os.replace`.
pytest 7.1.2 (2022-04-23)
=========================
Bug Fixes
---------
- `#9726 `_: An unnecessary ``numpy`` import inside :func:`pytest.approx` was removed.
- `#9820 `_: Fix comparison of ``dataclasses`` with ``InitVar``.
- `#9869 `_: Increase ``stacklevel`` for the ``NODE_CTOR_FSPATH_ARG`` deprecation to point to the
user's code, not pytest.
- `#9871 `_: Fix a bizarre (and fortunately rare) bug where the `temp_path` fixture could raise
an internal error while attempting to get the current user's username.
pytest 7.1.1 (2022-03-17)
=========================
Bug Fixes
---------
- `#9767 `_: Fixed a regression in pytest 7.1.0 where some conftest.py files outside of the source tree (e.g. in the `site-packages` directory) were not picked up.
pytest 7.1.0 (2022-03-13)
=========================
Breaking Changes
----------------
- `#8838 `_: As per our policy, the following features have been deprecated in the 6.X series and are now
removed:
* ``pytest._fillfuncargs`` function.
* ``pytest_warning_captured`` hook - use ``pytest_warning_recorded`` instead.
* ``-k -foobar`` syntax - use ``-k 'not foobar'`` instead.
* ``-k foobar:`` syntax.
* ``pytest.collect`` module - import from ``pytest`` directly.
For more information consult
`Deprecations and Removals `__ in the docs.
- `#9437 `_: Dropped support for Python 3.6, which reached `end-of-life `__ at 2021-12-23.
Improvements
------------
- `#5192 `_: Fixed test output for some data types where ``-v`` would show less information.
Also, when showing diffs for sequences, ``-q`` would produce full diffs instead of the expected diff.
- `#9362 `_: pytest now avoids specialized assert formatting when it is detected that the default ``__eq__`` is overridden in ``attrs`` or ``dataclasses``.
- `#9536 `_: When ``-vv`` is given on command line, show skipping and xfail reasons in full instead of truncating them to fit the terminal width.
- `#9644 `_: More information about the location of resources that led Python to raise :class:`ResourceWarning` can now
be obtained by enabling :mod:`tracemalloc`.
See :ref:`resource-warnings` for more information.
- `#9678 `_: More types are now accepted in the ``ids`` argument to ``@pytest.mark.parametrize``.
Previously only `str`, `float`, `int` and `bool` were accepted;
now `bytes`, `complex`, `re.Pattern`, `Enum` and anything with a `__name__` are also accepted.
- `#9692 `_: :func:`pytest.approx` now raises a :class:`TypeError` when given an unordered sequence (such as :class:`set`).
Note that this implies that custom classes which only implement ``__iter__`` and ``__len__`` are no longer supported as they don't guarantee order.
Bug Fixes
---------
- `#8242 `_: The deprecation of raising :class:`unittest.SkipTest` to skip collection of
tests during the pytest collection phase is reverted - this is now a supported
feature again.
- `#9493 `_: Symbolic link components are no longer resolved in conftest paths.
This means that if a conftest appears twice in collection tree, using symlinks, it will be executed twice.
For example, given
tests/real/conftest.py
tests/real/test_it.py
tests/link -> tests/real
running ``pytest tests`` now imports the conftest twice, once as ``tests/real/conftest.py`` and once as ``tests/link/conftest.py``.
This is a fix to match a similar change made to test collection itself in pytest 6.0 (see :pull:`6523` for details).
- `#9626 `_: Fixed count of selected tests on terminal collection summary when there were errors or skipped modules.
If there were errors or skipped modules on collection, pytest would mistakenly subtract those from the selected count.
- `#9645 `_: Fixed regression where ``--import-mode=importlib`` used together with :envvar:`PYTHONPATH` or :confval:`pythonpath` would cause import errors in test suites.
- `#9708 `_: :fixture:`pytester` now requests a :fixture:`monkeypatch` fixture instead of creating one internally. This solves some issues with tests that involve pytest environment variables.
- `#9730 `_: Malformed ``pyproject.toml`` files now produce a clearer error message.
pytest 7.0.1 (2022-02-11)
=========================
Bug Fixes
---------
- `#9608 `_: Fix invalid importing of ``importlib.readers`` in Python 3.9.
- `#9610 `_: Restore `UnitTestFunction.obj` to return unbound rather than bound method.
Fixes a crash during a failed teardown in unittest TestCases with non-default `__init__`.
Regressed in pytest 7.0.0.
- `#9636 `_: The ``pythonpath`` plugin was renamed to ``python_path``. This avoids a conflict with the ``pytest-pythonpath`` plugin.
- `#9642 `_: Fix running tests by id with ``::`` in the parametrize portion.
- `#9643 `_: Delay issuing a :class:`~pytest.PytestWarning` about diamond inheritance involving :class:`~pytest.Item` and
:class:`~pytest.Collector` so it can be filtered using :ref:`standard warning filters `.
pytest 7.0.0 (2022-02-03)
=========================
(**Please see the full set of changes for this release also in the 7.0.0rc1 notes below**)
Deprecations
------------
- `#9488 `_: If custom subclasses of nodes like :class:`pytest.Item` override the
``__init__`` method, they should take ``**kwargs``. See
:ref:`uncooperative-constructors-deprecated` for details.
Note that a deprection warning is only emitted when there is a conflict in the
arguments pytest expected to pass. This deprecation was already part of pytest
7.0.0rc1 but wasn't documented.
Bug Fixes
---------
- `#9355 `_: Fixed error message prints function decorators when using assert in Python 3.8 and above.
- `#9396 `_: Ensure :attr:`pytest.Config.inifile` is available during the :func:`pytest_cmdline_main <_pytest.hookspec.pytest_cmdline_main>` hook (regression during ``7.0.0rc1``).
Improved Documentation
----------------------
- `#9404 `_: Added extra documentation on alternatives to common misuses of `pytest.warns(None)` ahead of its deprecation.
- `#9505 `_: Clarify where the configuration files are located. To avoid confusions documentation mentions
that configuration file is located in the root of the repository.
Trivial/Internal Changes
------------------------
- `#9521 `_: Add test coverage to assertion rewrite path.
pytest 7.0.0rc1 (2021-12-06)
============================
Breaking Changes
----------------
- `#7259 `_: The :ref:`Node.reportinfo() ` function first return value type has been expanded from `py.path.local | str` to `os.PathLike[str] | str`.
Most plugins which refer to `reportinfo()` only define it as part of a custom :class:`pytest.Item` implementation.
Since `py.path.local` is a `os.PathLike[str]`, these plugins are unaffacted.
Plugins and users which call `reportinfo()`, use the first return value and interact with it as a `py.path.local`, would need to adjust by calling `py.path.local(fspath)`.
Although preferably, avoid the legacy `py.path.local` and use `pathlib.Path`, or use `item.location` or `item.path`, instead.
Note: pytest was not able to provide a deprecation period for this change.
- `#8246 `_: ``--version`` now writes version information to ``stdout`` rather than ``stderr``.
- `#8733 `_: Drop a workaround for `pyreadline `__ that made it work with ``--pdb``.
The workaround was introduced in `#1281 `__ in 2015, however since then
`pyreadline seems to have gone unmaintained `__, is `generating
warnings `__, and will stop working on Python 3.10.
- `#9061 `_: Using :func:`pytest.approx` in a boolean context now raises an error hinting at the proper usage.
It is apparently common for users to mistakenly use ``pytest.approx`` like this:
.. code-block:: python
assert pytest.approx(actual, expected)
While the correct usage is:
.. code-block:: python
assert actual == pytest.approx(expected)
The new error message helps catch those mistakes.
- `#9277 `_: The ``pytest.Instance`` collector type has been removed.
Importing ``pytest.Instance`` or ``_pytest.python.Instance`` returns a dummy type and emits a deprecation warning.
See :ref:`instance-collector-deprecation` for details.
- `#9308 `_: **PytestRemovedIn7Warning deprecation warnings are now errors by default.**
Following our plan to remove deprecated features with as little disruption as
possible, all warnings of type ``PytestRemovedIn7Warning`` now generate errors
instead of warning messages by default.
**The affected features will be effectively removed in pytest 7.1**, so please consult the
:ref:`deprecations` section in the docs for directions on how to update existing code.
In the pytest ``7.0.X`` series, it is possible to change the errors back into warnings as a
stopgap measure by adding this to your ``pytest.ini`` file:
.. code-block:: ini
[pytest]
filterwarnings =
ignore::pytest.PytestRemovedIn7Warning
But this will stop working when pytest ``7.1`` is released.
**If you have concerns** about the removal of a specific feature, please add a
comment to :issue:`9308`.
Deprecations
------------
- `#7259 `_: ``py.path.local`` arguments for hooks have been deprecated. See :ref:`the deprecation note ` for full details.
``py.path.local`` arguments to Node constructors have been deprecated. See :ref:`the deprecation note ` for full details.
.. note::
The name of the :class:`~_pytest.nodes.Node` arguments and attributes (the
new attribute being ``path``) is **the opposite** of the situation for hooks
(the old argument being ``path``).
This is an unfortunate artifact due to historical reasons, which should be
resolved in future versions as we slowly get rid of the :pypi:`py`
dependency (see :issue:`9283` for a longer discussion).
- `#7469 `_: Directly constructing the following classes is now deprecated:
- ``_pytest.mark.structures.Mark``
- ``_pytest.mark.structures.MarkDecorator``
- ``_pytest.mark.structures.MarkGenerator``
- ``_pytest.python.Metafunc``
- ``_pytest.runner.CallInfo``
- ``_pytest._code.ExceptionInfo``
- ``_pytest.config.argparsing.Parser``
- ``_pytest.config.argparsing.OptionGroup``
- ``_pytest.pytester.HookRecorder``
These constructors have always been considered private, but now issue a deprecation warning, which may become a hard error in pytest 8.
- `#8242 `_: Raising :class:`unittest.SkipTest` to skip collection of tests during the
pytest collection phase is deprecated. Use :func:`pytest.skip` instead.
Note: This deprecation only relates to using :class:`unittest.SkipTest` during test
collection. You are probably not doing that. Ordinary usage of
:class:`unittest.SkipTest` / :meth:`unittest.TestCase.skipTest` /
:func:`unittest.skip` in unittest test cases is fully supported.
.. note:: This deprecation has been reverted in pytest 7.1.0.
- `#8315 `_: Several behaviors of :meth:`Parser.addoption ` are now
scheduled for removal in pytest 8 (deprecated since pytest 2.4.0):
- ``parser.addoption(..., help=".. %default ..")`` - use ``%(default)s`` instead.
- ``parser.addoption(..., type="int/string/float/complex")`` - use ``type=int`` etc. instead.
- `#8447 `_: Defining a custom pytest node type which is both an :class:`pytest.Item - ` and a :class:`pytest.Collector ` (e.g. :class:`pytest.File `) now issues a warning.
It was never sanely supported and triggers hard to debug errors.
See :ref:`the deprecation note ` for full details.
- `#8592 `_: :hook:`pytest_cmdline_preparse` has been officially deprecated. It will be removed in a future release. Use :hook:`pytest_load_initial_conftests` instead.
See :ref:`the deprecation note ` for full details.
- `#8645 `_: :func:`pytest.warns(None) ` is now deprecated because many people used
it to mean "this code does not emit warnings", but it actually had the effect of
checking that the code emits at least one warning of any type - like ``pytest.warns()``
or ``pytest.warns(Warning)``.
- `#8948 `_: :func:`pytest.skip(msg=...) `, :func:`pytest.fail(msg=...) ` and :func:`pytest.exit(msg=...) `
signatures now accept a ``reason`` argument instead of ``msg``. Using ``msg`` still works, but is deprecated and will be removed in a future release.
This was changed for consistency with :func:`pytest.mark.skip ` and :func:`pytest.mark.xfail ` which both accept
``reason`` as an argument.
- `#8174 `_: The following changes have been made to types reachable through :attr:`pytest.ExceptionInfo.traceback`:
- The ``path`` property of ``_pytest.code.Code`` returns ``Path`` instead of ``py.path.local``.
- The ``path`` property of ``_pytest.code.TracebackEntry`` returns ``Path`` instead of ``py.path.local``.
There was no deprecation period for this change (sorry!).
Features
--------
- `#5196 `_: Tests are now ordered by definition order in more cases.
In a class hierarchy, tests from base classes are now consistently ordered before tests defined on their subclasses (reverse MRO order).
- `#7132 `_: Added two environment variables :envvar:`PYTEST_THEME` and :envvar:`PYTEST_THEME_MODE` to let the users customize the pygments theme used.
- `#7259 `_: Added :meth:`cache.mkdir() `, which is similar to the existing :meth:`cache.makedir() `,
but returns a :class:`pathlib.Path` instead of a legacy ``py.path.local``.
Added a ``paths`` type to :meth:`parser.addini() `,
as in ``parser.addini("mypaths", "my paths", type="paths")``,
which is similar to the existing ``pathlist``,
but returns a list of :class:`pathlib.Path` instead of legacy ``py.path.local``.
- `#7469 `_: The types of objects used in pytest's API are now exported so they may be used in type annotations.
The newly-exported types are:
- ``pytest.Config`` for :class:`Config `.
- ``pytest.Mark`` for :class:`marks `.
- ``pytest.MarkDecorator`` for :class:`mark decorators `.
- ``pytest.MarkGenerator`` for the :class:`pytest.mark ` singleton.
- ``pytest.Metafunc`` for the :class:`metafunc ` argument to the :hook:`pytest_generate_tests` hook.
- ``pytest.CallInfo`` for the :class:`CallInfo ` type passed to various hooks.
- ``pytest.PytestPluginManager`` for :class:`PytestPluginManager `.
- ``pytest.ExceptionInfo`` for the :class:`ExceptionInfo ` type returned from :func:`pytest.raises` and passed to various hooks.
- ``pytest.Parser`` for the :class:`Parser ` type passed to the :hook:`pytest_addoption` hook.
- ``pytest.OptionGroup`` for the :class:`OptionGroup ` type returned from the :func:`parser.addgroup ` method.
- ``pytest.HookRecorder`` for the :class:`HookRecorder ` type returned from :class:`~pytest.Pytester`.
- ``pytest.RecordedHookCall`` for the :class:`RecordedHookCall ` type returned from :class:`~pytest.HookRecorder`.
- ``pytest.RunResult`` for the :class:`RunResult ` type returned from :class:`~pytest.Pytester`.
- ``pytest.LineMatcher`` for the :class:`LineMatcher ` type used in :class:`~pytest.RunResult` and others.
- ``pytest.TestReport`` for the :class:`TestReport ` type used in various hooks.
- ``pytest.CollectReport`` for the :class:`CollectReport ` type used in various hooks.
Constructing most of them directly is not supported; they are only meant for use in type annotations.
Doing so will emit a deprecation warning, and may become a hard-error in pytest 8.0.
Subclassing them is also not supported. This is not currently enforced at runtime, but is detected by type-checkers such as mypy.
- `#7856 `_: :ref:`--import-mode=importlib ` now works with features that
depend on modules being on :py:data:`sys.modules`, such as :mod:`pickle` and :mod:`dataclasses`.
- `#8144 `_: The following hooks now receive an additional ``pathlib.Path`` argument, equivalent to an existing ``py.path.local`` argument:
- :hook:`pytest_ignore_collect` - The ``collection_path`` parameter (equivalent to existing ``path`` parameter).
- :hook:`pytest_collect_file` - The ``file_path`` parameter (equivalent to existing ``path`` parameter).
- :hook:`pytest_pycollect_makemodule` - The ``module_path`` parameter (equivalent to existing ``path`` parameter).
- :hook:`pytest_report_header` - The ``start_path`` parameter (equivalent to existing ``startdir`` parameter).
- :hook:`pytest_report_collectionfinish` - The ``start_path`` parameter (equivalent to existing ``startdir`` parameter).
.. note::
The name of the :class:`~_pytest.nodes.Node` arguments and attributes (the
new attribute being ``path``) is **the opposite** of the situation for hooks
(the old argument being ``path``).
This is an unfortunate artifact due to historical reasons, which should be
resolved in future versions as we slowly get rid of the :pypi:`py`
dependency (see :issue:`9283` for a longer discussion).
- `#8251 `_: Implement ``Node.path`` as a ``pathlib.Path``. Both the old ``fspath`` and this new attribute gets set no matter whether ``path`` or ``fspath`` (deprecated) is passed to the constructor. It is a replacement for the ``fspath`` attribute (which represents the same path as ``py.path.local``). While ``fspath`` is not deprecated yet
due to the ongoing migration of methods like :meth:`~_pytest.Item.reportinfo`, we expect to deprecate it in a future release.
.. note::
The name of the :class:`~_pytest.nodes.Node` arguments and attributes (the
new attribute being ``path``) is **the opposite** of the situation for hooks
(the old argument being ``path``).
This is an unfortunate artifact due to historical reasons, which should be
resolved in future versions as we slowly get rid of the :pypi:`py`
dependency (see :issue:`9283` for a longer discussion).
- `#8421 `_: :func:`pytest.approx` now works on :class:`~decimal.Decimal` within mappings/dicts and sequences/lists.
- `#8606 `_: pytest invocations with ``--fixtures-per-test`` and ``--fixtures`` have been enriched with:
- Fixture location path printed with the fixture name.
- First section of the fixture's docstring printed under the fixture name.
- Whole of fixture's docstring printed under the fixture name using ``--verbose`` option.
- `#8761 `_: New :ref:`version-tuple` attribute, which makes it simpler for users to do something depending on the pytest version (such as declaring hooks which are introduced in later versions).
- `#8789 `_: Switch TOML parser from ``toml`` to ``tomli`` for TOML v1.0.0 support in ``pyproject.toml``.
- `#8920 `_: Added :class:`pytest.Stash`, a facility for plugins to store their data on :class:`~pytest.Config` and :class:`~_pytest.nodes.Node`\s in a type-safe and conflict-free manner.
See :ref:`plugin-stash` for details.
- `#8953 `_: :class:`RunResult <_pytest.pytester.RunResult>` method :meth:`assert_outcomes <_pytest.pytester.RunResult.assert_outcomes>` now accepts a
``warnings`` argument to assert the total number of warnings captured.
- `#8954 `_: ``--debug`` flag now accepts a :class:`str` file to route debug logs into, remains defaulted to `pytestdebug.log`.
- `#9023 `_: Full diffs are now always shown for equality assertions of iterables when
`CI` or ``BUILD_NUMBER`` is found in the environment, even when ``-v`` isn't
used.
- `#9113 `_: :class:`RunResult <_pytest.pytester.RunResult>` method :meth:`assert_outcomes <_pytest.pytester.RunResult.assert_outcomes>` now accepts a
``deselected`` argument to assert the total number of deselected tests.
- `#9114 `_: Added :confval:`pythonpath` setting that adds listed paths to :data:`sys.path` for the duration of the test session. If you currently use the pytest-pythonpath or pytest-srcpaths plugins, you should be able to replace them with built-in `pythonpath` setting.
Improvements
------------
- `#7480 `_: A deprecation scheduled to be removed in a major version X (e.g. pytest 7, 8, 9, ...) now uses warning category `PytestRemovedInXWarning`,
a subclass of :class:`~pytest.PytestDeprecationWarning`,
instead of :class:`PytestDeprecationWarning` directly.
See :ref:`backwards-compatibility` for more details.
- `#7864 `_: Improved error messages when parsing warning filters.
Previously pytest would show an internal traceback, which besides being ugly sometimes would hide the cause
of the problem (for example an ``ImportError`` while importing a specific warning type).
- `#8335 `_: Improved :func:`pytest.approx` assertion messages for sequences of numbers.
The assertion messages now dumps a table with the index and the error of each diff.
Example::
> assert [1, 2, 3, 4] == pytest.approx([1, 3, 3, 5])
E assert comparison failed for 2 values:
E Index | Obtained | Expected
E 1 | 2 | 3 +- 3.0e-06
E 3 | 4 | 5 +- 5.0e-06
- `#8403 `_: By default, pytest will truncate long strings in assert errors so they don't clutter the output too much,
currently at ``240`` characters by default.
However, in some cases the longer output helps, or is even crucial, to diagnose a failure. Using ``-v`` will
now increase the truncation threshold to ``2400`` characters, and ``-vv`` or higher will disable truncation entirely.
- `#8509 `_: Fixed issue where :meth:`unittest.TestCase.setUpClass` is not called when a test has `/` in its name since pytest 6.2.0.
This refers to the path part in pytest node IDs, e.g. ``TestClass::test_it`` in the node ID ``tests/test_file.py::TestClass::test_it``.
Now, instead of assuming that the test name does not contain ``/``, it is assumed that test path does not contain ``::``. We plan to hopefully make both of these work in the future.
- `#8803 `_: It is now possible to add colors to custom log levels on cli log.
By using :func:`add_color_level <_pytest.logging.add_color_level>` from a ``pytest_configure`` hook, colors can be added::
logging_plugin = config.pluginmanager.get_plugin('logging-plugin')
logging_plugin.log_cli_handler.formatter.add_color_level(logging.INFO, 'cyan')
logging_plugin.log_cli_handler.formatter.add_color_level(logging.SPAM, 'blue')
See :ref:`log_colors` for more information.
- `#8822 `_: When showing fixture paths in `--fixtures` or `--fixtures-by-test`, fixtures coming from pytest itself now display an elided path, rather than the full path to the file in the `site-packages` directory.
- `#8898 `_: Complex numbers are now treated like floats and integers when generating parameterization IDs.
- `#9062 `_: ``--stepwise-skip`` now implicitly enables ``--stepwise`` and can be used on its own.
- `#9205 `_: :meth:`pytest.Cache.set` now preserves key order when saving dicts.
Bug Fixes
---------
- `#7124 `_: Fixed an issue where ``__main__.py`` would raise an ``ImportError`` when ``--doctest-modules`` was provided.
- `#8061 `_: Fixed failing ``staticmethod`` test cases if they are inherited from a parent test class.
- `#8192 `_: ``testdir.makefile`` now silently accepts values which don't start with ``.`` to maintain backward compatibility with older pytest versions.
``pytester.makefile`` now issues a clearer error if the ``.`` is missing in the ``ext`` argument.
- `#8258 `_: Fixed issue where pytest's ``faulthandler`` support would not dump traceback on crashes
if the :mod:`faulthandler` module was already enabled during pytest startup (using
``python -X dev -m pytest`` for example).
- `#8317 `_: Fixed an issue where illegal directory characters derived from ``getpass.getuser()`` raised an ``OSError``.
- `#8367 `_: Fix ``Class.from_parent`` so it forwards extra keyword arguments to the constructor.
- `#8377 `_: The test selection options ``pytest -k`` and ``pytest -m`` now support matching
names containing forward slash (``/``) characters.
- `#8384 `_: The ``@pytest.mark.skip`` decorator now correctly handles its arguments. When the ``reason`` argument is accidentally given both positional and as a keyword (e.g. because it was confused with ``skipif``), a ``TypeError`` now occurs. Before, such tests were silently skipped, and the positional argument ignored. Additionally, ``reason`` is now documented correctly as positional or keyword (rather than keyword-only).
- `#8394 `_: Use private names for internal fixtures that handle classic setup/teardown so that they don't show up with the default ``--fixtures`` invocation (but they still show up with ``--fixtures -v``).
- `#8456 `_: The :confval:`required_plugins` config option now works correctly when pre-releases of plugins are installed, rather than falsely claiming that those plugins aren't installed at all.
- `#8464 `_: ``-c `` now also properly defines ``rootdir`` as the directory that contains ````.
- `#8503 `_: :meth:`pytest.MonkeyPatch.syspath_prepend` no longer fails when
``setuptools`` is not installed.
It now only calls :func:`pkg_resources.fixup_namespace_packages` if
``pkg_resources`` was previously imported, because it is not needed otherwise.
- `#8548 `_: Introduce fix to handle precision width in ``log-cli-format`` in turn to fix output coloring for certain formats.
- `#8796 `_: Fixed internal error when skipping doctests.
- `#8983 `_: The test selection options ``pytest -k`` and ``pytest -m`` now support matching names containing backslash (`\\`) characters.
Backslashes are treated literally, not as escape characters (the values being matched against are already escaped).
- `#8990 `_: Fix `pytest -vv` crashing with an internal exception `AttributeError: 'str' object has no attribute 'relative_to'` in some cases.
- `#9077 `_: Fixed confusing error message when ``request.fspath`` / ``request.path`` was accessed from a session-scoped fixture.
- `#9131 `_: Fixed the URL used by ``--pastebin`` to use `bpa.st `__.
- `#9163 `_: The end line number and end column offset are now properly set for rewritten assert statements.
- `#9169 `_: Support for the ``files`` API from ``importlib.resources`` within rewritten files.
- `#9272 `_: The nose compatibility module-level fixtures `setup()` and `teardown()` are now only called once per module, instead of for each test function.
They are now called even if object-level `setup`/`teardown` is defined.
Improved Documentation
----------------------
- `#4320 `_: Improved docs for `pytester.copy_example`.
- `#5105 `_: Add automatically generated :ref:`plugin-list`. The list is updated on a periodic schedule.
- `#8337 `_: Recommend `numpy.testing `__ module on :func:`pytest.approx` documentation.
- `#8655 `_: Help text for ``--pdbcls`` more accurately reflects the option's behavior.
- `#9210 `_: Remove incorrect docs about ``confcutdir`` being a configuration option: it can only be set through the ``--confcutdir`` command-line option.
- `#9242 `_: Upgrade readthedocs configuration to use a `newer Ubuntu version `__` with better unicode support for PDF docs.
- `#9341 `_: Various methods commonly used for :ref:`non-python tests` are now correctly documented in the reference docs. They were undocumented previously.
Trivial/Internal Changes
------------------------
- `#8133 `_: Migrate to ``setuptools_scm`` 6.x to use ``SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYTEST`` for more robust release tooling.
- `#8174 `_: The following changes have been made to internal pytest types/functions:
- The ``_pytest.code.getfslineno()`` function returns ``Path`` instead of ``py.path.local``.
- The ``_pytest.python.path_matches_patterns()`` function takes ``Path`` instead of ``py.path.local``.
- The ``_pytest._code.Traceback.cut()`` function accepts any ``os.PathLike[str]``, not just ``py.path.local``.
- `#8248 `_: Internal Restructure: let ``python.PyObjMixin`` inherit from ``nodes.Node`` to carry over typing information.
- `#8432 `_: Improve error message when :func:`pytest.skip` is used at module level without passing `allow_module_level=True`.
- `#8818 `_: Ensure ``regendoc`` opts out of ``TOX_ENV`` cachedir selection to ensure independent example test runs.
- `#8913 `_: The private ``CallSpec2._arg2scopenum`` attribute has been removed after an internal refactoring.
- `#8967 `_: :hook:`pytest_assertion_pass` is no longer considered experimental and
future changes to it will be considered more carefully.
- `#9202 `_: Add github action to upload coverage report to codecov instead of bash uploader.
- `#9225 `_: Changed the command used to create sdist and wheel artifacts: using the build package instead of setup.py.
- `#9351 `_: Correct minor typos in doc/en/example/special.rst.
pytest 6.2.5 (2021-08-29)
=========================
Trivial/Internal Changes
------------------------
- :issue:`8494`: Python 3.10 is now supported.
- :issue:`9040`: Enable compatibility with ``pluggy 1.0`` or later.
pytest 6.2.4 (2021-05-04)
=========================
Bug Fixes
---------
- :issue:`8539`: Fixed assertion rewriting on Python 3.10.
pytest 6.2.3 (2021-04-03)
=========================
Bug Fixes
---------
- :issue:`8414`: pytest used to create directories under ``/tmp`` with world-readable
permissions. This means that any user in the system was able to read
information written by tests in temporary directories (such as those created by
the ``tmp_path``/``tmpdir`` fixture). Now the directories are created with
private permissions.
pytest used to silently use a pre-existing ``/tmp/pytest-of-`` directory,
even if owned by another user. This means another user could pre-create such a
directory and gain control of another user's temporary directory. Now such a
condition results in an error.
pytest 6.2.2 (2021-01-25)
=========================
Bug Fixes
---------
- :issue:`8152`: Fixed "()" being shown as a skip reason in the verbose test summary line when the reason is empty.
- :issue:`8249`: Fix the ``faulthandler`` plugin for occasions when running with ``twisted.logger`` and using ``pytest --capture=no``.
pytest 6.2.1 (2020-12-15)
=========================
Bug Fixes
---------
- :issue:`7678`: Fixed bug where ``ImportPathMismatchError`` would be raised for files compiled in
the host and loaded later from an UNC mounted path (Windows).
- :issue:`8132`: Fixed regression in ``approx``: in 6.2.0 ``approx`` no longer raises
``TypeError`` when dealing with non-numeric types, falling back to normal comparison.
Before 6.2.0, array types like tf.DeviceArray fell through to the scalar case,
and happened to compare correctly to a scalar if they had only one element.
After 6.2.0, these types began failing, because they inherited neither from
standard Python number hierarchy nor from ``numpy.ndarray``.
``approx`` now converts arguments to ``numpy.ndarray`` if they expose the array
protocol and are not scalars. This treats array-like objects like numpy arrays,
regardless of size.
pytest 6.2.0 (2020-12-12)
=========================
Breaking Changes
----------------
- :issue:`7808`: pytest now supports python3.6+ only.
Deprecations
------------
- :issue:`7469`: Directly constructing/calling the following classes/functions is now deprecated:
- ``_pytest.cacheprovider.Cache``
- ``_pytest.cacheprovider.Cache.for_config()``
- ``_pytest.cacheprovider.Cache.clear_cache()``
- ``_pytest.cacheprovider.Cache.cache_dir_from_config()``
- ``_pytest.capture.CaptureFixture``
- ``_pytest.fixtures.FixtureRequest``
- ``_pytest.fixtures.SubRequest``
- ``_pytest.logging.LogCaptureFixture``
- ``_pytest.pytester.Pytester``
- ``_pytest.pytester.Testdir``
- ``_pytest.recwarn.WarningsRecorder``
- ``_pytest.recwarn.WarningsChecker``
- ``_pytest.tmpdir.TempPathFactory``
- ``_pytest.tmpdir.TempdirFactory``
These have always been considered private, but now issue a deprecation warning, which may become a hard error in pytest 8.0.0.
- :issue:`7530`: The ``--strict`` command-line option has been deprecated, use ``--strict-markers`` instead.
We have plans to maybe in the future to reintroduce ``--strict`` and make it an encompassing flag for all strictness
related options (``--strict-markers`` and ``--strict-config`` at the moment, more might be introduced in the future).
- :issue:`7988`: The ``@pytest.yield_fixture`` decorator/function is now deprecated. Use :func:`pytest.fixture` instead.
``yield_fixture`` has been an alias for ``fixture`` for a very long time, so can be search/replaced safely.
Features
--------
- :issue:`5299`: pytest now warns about unraisable exceptions and unhandled thread exceptions that occur in tests on Python>=3.8.
See :ref:`unraisable` for more information.
- :issue:`7425`: New :fixture:`pytester` fixture, which is identical to :fixture:`testdir` but its methods return :class:`pathlib.Path` when appropriate instead of ``py.path.local``.
This is part of the movement to use :class:`pathlib.Path` objects internally, in order to remove the dependency to ``py`` in the future.
Internally, the old :class:`Testdir <_pytest.pytester.Testdir>` is now a thin wrapper around :class:`Pytester <_pytest.pytester.Pytester>`, preserving the old interface.
- :issue:`7695`: A new hook was added, `pytest_markeval_namespace` which should return a dictionary.
This dictionary will be used to augment the "global" variables available to evaluate skipif/xfail/xpass markers.
Pseudo example
``conftest.py``:
.. code-block:: python
def pytest_markeval_namespace():
return {"color": "red"}
``test_func.py``:
.. code-block:: python
@pytest.mark.skipif("color == 'blue'", reason="Color is not red")
def test_func():
assert False
- :issue:`8006`: It is now possible to construct a :class:`~pytest.MonkeyPatch` object directly as ``pytest.MonkeyPatch()``,
in cases when the :fixture:`monkeypatch` fixture cannot be used. Previously some users imported it
from the private `_pytest.monkeypatch.MonkeyPatch` namespace.
Additionally, :meth:`MonkeyPatch.context ` is now a classmethod,
and can be used as ``with MonkeyPatch.context() as mp: ...``. This is the recommended way to use
``MonkeyPatch`` directly, since unlike the ``monkeypatch`` fixture, an instance created directly
is not ``undo()``-ed automatically.
Improvements
------------
- :issue:`1265`: Added an ``__str__`` implementation to the :class:`~pytest.pytester.LineMatcher` class which is returned from ``pytester.run_pytest().stdout`` and similar. It returns the entire output, like the existing ``str()`` method.
- :issue:`2044`: Verbose mode now shows the reason that a test was skipped in the test's terminal line after the "SKIPPED", "XFAIL" or "XPASS".
- :issue:`7469` The types of builtin pytest fixtures are now exported so they may be used in type annotations of test functions.
The newly-exported types are:
- ``pytest.FixtureRequest`` for the :fixture:`request` fixture.
- ``pytest.Cache`` for the :fixture:`cache` fixture.
- ``pytest.CaptureFixture[str]`` for the :fixture:`capfd` and :fixture:`capsys` fixtures.
- ``pytest.CaptureFixture[bytes]`` for the :fixture:`capfdbinary` and :fixture:`capsysbinary` fixtures.
- ``pytest.LogCaptureFixture`` for the :fixture:`caplog` fixture.
- ``pytest.Pytester`` for the :fixture:`pytester` fixture.
- ``pytest.Testdir`` for the :fixture:`testdir` fixture.
- ``pytest.TempdirFactory`` for the :fixture:`tmpdir_factory` fixture.
- ``pytest.TempPathFactory`` for the :fixture:`tmp_path_factory` fixture.
- ``pytest.MonkeyPatch`` for the :fixture:`monkeypatch` fixture.
- ``pytest.WarningsRecorder`` for the :fixture:`recwarn` fixture.
Constructing them is not supported (except for `MonkeyPatch`); they are only meant for use in type annotations.
Doing so will emit a deprecation warning, and may become a hard-error in pytest 8.0.
Subclassing them is also not supported. This is not currently enforced at runtime, but is detected by type-checkers such as mypy.
- :issue:`7527`: When a comparison between :func:`namedtuple ` instances of the same type fails, pytest now shows the differing field names (possibly nested) instead of their indexes.
- :issue:`7615`: :meth:`Node.warn <_pytest.nodes.Node.warn>` now permits any subclass of :class:`Warning`, not just :class:`PytestWarning `.
- :issue:`7701`: Improved reporting when using ``--collected-only``. It will now show the number of collected tests in the summary stats.
- :issue:`7710`: Use strict equality comparison for non-numeric types in :func:`pytest.approx` instead of
raising :class:`TypeError`.
This was the undocumented behavior before 3.7, but is now officially a supported feature.
- :issue:`7938`: New ``--sw-skip`` argument which is a shorthand for ``--stepwise-skip``.
- :issue:`8023`: Added ``'node_modules'`` to default value for :confval:`norecursedirs`.
- :issue:`8032`: :meth:`doClassCleanups ` (introduced in :mod:`unittest` in Python and 3.8) is now called appropriately.
Bug Fixes
---------
- :issue:`4824`: Fixed quadratic behavior and improved performance of collection of items using autouse fixtures and xunit fixtures.
- :issue:`7758`: Fixed an issue where some files in packages are getting lost from ``--lf`` even though they contain tests that failed. Regressed in pytest 5.4.0.
- :issue:`7911`: Directories created by by :fixture:`tmp_path` and :fixture:`tmpdir` are now considered stale after 3 days without modification (previous value was 3 hours) to avoid deleting directories still in use in long running test suites.
- :issue:`7913`: Fixed a crash or hang in :meth:`pytester.spawn <_pytest.pytester.Pytester.spawn>` when the :mod:`readline` module is involved.
- :issue:`7951`: Fixed handling of recursive symlinks when collecting tests.
- :issue:`7981`: Fixed symlinked directories not being followed during collection. Regressed in pytest 6.1.0.
- :issue:`8016`: Fixed only one doctest being collected when using ``pytest --doctest-modules path/to/an/__init__.py``.
Improved Documentation
----------------------
- :issue:`7429`: Add more information and use cases about skipping doctests.
- :issue:`7780`: Classes which should not be inherited from are now marked ``final class`` in the API reference.
- :issue:`7872`: ``_pytest.config.argparsing.Parser.addini()`` accepts explicit ``None`` and ``"string"``.
- :issue:`7878`: In pull request section, ask to commit after editing changelog and authors file.
Trivial/Internal Changes
------------------------
- :issue:`7802`: The ``attrs`` dependency requirement is now >=19.2.0 instead of >=17.4.0.
- :issue:`8014`: `.pyc` files created by pytest's assertion rewriting now conform to the newer :pep:`552` format on Python>=3.7.
(These files are internal and only interpreted by pytest itself.)
pytest 6.1.2 (2020-10-28)
=========================
Bug Fixes
---------
- :issue:`7758`: Fixed an issue where some files in packages are getting lost from ``--lf`` even though they contain tests that failed. Regressed in pytest 5.4.0.
- :issue:`7911`: Directories created by `tmpdir` are now considered stale after 3 days without modification (previous value was 3 hours) to avoid deleting directories still in use in long running test suites.
Improved Documentation
----------------------
- :issue:`7815`: Improve deprecation warning message for ``pytest._fillfuncargs()``.
pytest 6.1.1 (2020-10-03)
=========================
Bug Fixes
---------
- :issue:`7807`: Fixed regression in pytest 6.1.0 causing incorrect rootdir to be determined in some non-trivial cases where parent directories have config files as well.
- :issue:`7814`: Fixed crash in header reporting when :confval:`testpaths` is used and contains absolute paths (regression in 6.1.0).
pytest 6.1.0 (2020-09-26)
=========================
Breaking Changes
----------------
- :issue:`5585`: As per our policy, the following features which have been deprecated in the 5.X series are now
removed:
* The ``funcargnames`` read-only property of ``FixtureRequest``, ``Metafunc``, and ``Function`` classes. Use ``fixturenames`` attribute.
* ``@pytest.fixture`` no longer supports positional arguments, pass all arguments by keyword instead.
* Direct construction of ``Node`` subclasses now raise an error, use ``from_parent`` instead.
* The default value for ``junit_family`` has changed to ``xunit2``. If you require the old format, add ``junit_family=xunit1`` to your configuration file.
* The ``TerminalReporter`` no longer has a ``writer`` attribute. Plugin authors may use the public functions of the ``TerminalReporter`` instead of accessing the ``TerminalWriter`` object directly.
* The ``--result-log`` option has been removed. Users are recommended to use the `pytest-reportlog `__ plugin instead.
For more information consult :std:doc:`deprecations` in the docs.
Deprecations
------------
- :issue:`6981`: The ``pytest.collect`` module is deprecated: all its names can be imported from ``pytest`` directly.
- :issue:`7097`: The ``pytest._fillfuncargs`` function is deprecated. This function was kept
for backward compatibility with an older plugin.
It's functionality is not meant to be used directly, but if you must replace
it, use `function._request._fillfixtures()` instead, though note this is not
a public API and may break in the future.
- :issue:`7210`: The special ``-k '-expr'`` syntax to ``-k`` is deprecated. Use ``-k 'not expr'``
instead.
The special ``-k 'expr:'`` syntax to ``-k`` is deprecated. Please open an issue
if you use this and want a replacement.
- :issue:`7255`: The :hook:`pytest_warning_captured` hook is deprecated in favor
of :hook:`pytest_warning_recorded`, and will be removed in a future version.
- :issue:`7648`: The ``gethookproxy()`` and ``isinitpath()`` methods of ``FSCollector`` and ``Package`` are deprecated;
use ``self.session.gethookproxy()`` and ``self.session.isinitpath()`` instead.
This should work on all pytest versions.
Features
--------
- :issue:`7667`: New ``--durations-min`` command-line flag controls the minimal duration for inclusion in the slowest list of tests shown by ``--durations``. Previously this was hard-coded to ``0.005s``.
Improvements
------------
- :issue:`6681`: Internal pytest warnings issued during the early stages of initialization are now properly handled and can filtered through :confval:`filterwarnings` or ``--pythonwarnings/-W``.
This also fixes a number of long standing issues: :issue:`2891`, :issue:`7620`, :issue:`7426`.
- :issue:`7572`: When a plugin listed in ``required_plugins`` is missing or an unknown config key is used with ``--strict-config``, a simple error message is now shown instead of a stacktrace.
- :issue:`7685`: Added two new attributes :attr:`rootpath <_pytest.config.Config.rootpath>` and :attr:`inipath <_pytest.config.Config.inipath>` to :class:`Config <_pytest.config.Config>`.
These attributes are :class:`pathlib.Path` versions of the existing :attr:`rootdir <_pytest.config.Config.rootdir>` and :attr:`inifile <_pytest.config.Config.inifile>` attributes,
and should be preferred over them when possible.
- :issue:`7780`: Public classes which are not designed to be inherited from are now marked :func:`@final `.
Code which inherits from these classes will trigger a type-checking (e.g. mypy) error, but will still work in runtime.
Currently the ``final`` designation does not appear in the API Reference but hopefully will in the future.
Bug Fixes
---------
- :issue:`1953`: Fixed error when overwriting a parametrized fixture, while also reusing the super fixture value.
.. code-block:: python
# conftest.py
import pytest
@pytest.fixture(params=[1, 2])
def foo(request):
return request.param
# test_foo.py
import pytest
@pytest.fixture
def foo(foo):
return foo * 2
- :issue:`4984`: Fixed an internal error crash with ``IndexError: list index out of range`` when
collecting a module which starts with a decorated function, the decorator
raises, and assertion rewriting is enabled.
- :issue:`7591`: pylint shouldn't complain anymore about unimplemented abstract methods when inheriting from :ref:`File `.
- :issue:`7628`: Fixed test collection when a full path without a drive letter was passed to pytest on Windows (for example ``\projects\tests\test.py`` instead of ``c:\projects\tests\pytest.py``).
- :issue:`7638`: Fix handling of command-line options that appear as paths but trigger an OS-level syntax error on Windows, such as the options used internally by ``pytest-xdist``.
- :issue:`7742`: Fixed INTERNALERROR when accessing locals / globals with faulty ``exec``.
Improved Documentation
----------------------
- :issue:`1477`: Removed faq.rst and its reference in contents.rst.
Trivial/Internal Changes
------------------------
- :issue:`7536`: The internal ``junitxml`` plugin has rewritten to use ``xml.etree.ElementTree``.
The order of attributes in XML elements might differ. Some unneeded escaping is
no longer performed.
- :issue:`7587`: The dependency on the ``more-itertools`` package has been removed.
- :issue:`7631`: The result type of :meth:`capfd.readouterr() <_pytest.capture.CaptureFixture.readouterr>` (and similar) is no longer a namedtuple,
but should behave like one in all respects. This was done for technical reasons.
- :issue:`7671`: When collecting tests, pytest finds test classes and functions by examining the
attributes of python objects (modules, classes and instances). To speed up this
process, pytest now ignores builtin attributes (like ``__class__``,
``__delattr__`` and ``__new__``) without consulting the :confval:`python_classes` and
:confval:`python_functions` configuration options and without passing them to plugins
using the :hook:`pytest_pycollect_makeitem` hook.
pytest 6.0.2 (2020-09-04)
=========================
Bug Fixes
---------
- :issue:`7148`: Fixed ``--log-cli`` potentially causing unrelated ``print`` output to be swallowed.
- :issue:`7672`: Fixed log-capturing level restored incorrectly if ``caplog.set_level`` is called more than once.
- :issue:`7686`: Fixed `NotSetType.token` being used as the parameter ID when the parametrization list is empty.
Regressed in pytest 6.0.0.
- :issue:`7707`: Fix internal error when handling some exceptions that contain multiple lines or the style uses multiple lines (``--tb=line`` for example).
pytest 6.0.1 (2020-07-30)
=========================
Bug Fixes
---------
- :issue:`7394`: Passing an empty ``help`` value to ``Parser.add_option`` is now accepted instead of crashing when running ``pytest --help``.
Passing ``None`` raises a more informative ``TypeError``.
- :issue:`7558`: Fix pylint ``not-callable`` lint on ``pytest.mark.parametrize()`` and the other builtin marks:
``skip``, ``skipif``, ``xfail``, ``usefixtures``, ``filterwarnings``.
- :issue:`7559`: Fix regression in plugins using ``TestReport.longreprtext`` (such as ``pytest-html``) when ``TestReport.longrepr`` is not a string.
- :issue:`7569`: Fix logging capture handler's level not reset on teardown after a call to ``caplog.set_level()``.
pytest 6.0.0 (2020-07-28)
=========================
(**Please see the full set of changes for this release also in the 6.0.0rc1 notes below**)
Breaking Changes
----------------
- :issue:`5584`: **PytestDeprecationWarning are now errors by default.**
Following our plan to remove deprecated features with as little disruption as
possible, all warnings of type ``PytestDeprecationWarning`` now generate errors
instead of warning messages.
**The affected features will be effectively removed in pytest 6.1**, so please consult the
:std:doc:`deprecations` section in the docs for directions on how to update existing code.
In the pytest ``6.0.X`` series, it is possible to change the errors back into warnings as a
stopgap measure by adding this to your ``pytest.ini`` file:
.. code-block:: ini
[pytest]
filterwarnings =
ignore::pytest.PytestDeprecationWarning
But this will stop working when pytest ``6.1`` is released.
**If you have concerns** about the removal of a specific feature, please add a
comment to :issue:`5584`.
- :issue:`7472`: The ``exec_()`` and ``is_true()`` methods of ``_pytest._code.Frame`` have been removed.
Features
--------
- :issue:`7464`: Added support for :envvar:`NO_COLOR` and :envvar:`FORCE_COLOR` environment variables to control colored output.
Improvements
------------
- :issue:`7467`: ``--log-file`` CLI option and ``log_file`` ini marker now create subdirectories if needed.
- :issue:`7489`: The :func:`pytest.raises` function has a clearer error message when ``match`` equals the obtained string but is not a regex match. In this case it is suggested to escape the regex.
Bug Fixes
---------
- :issue:`7392`: Fix the reported location of tests skipped with ``@pytest.mark.skip`` when ``--runxfail`` is used.
- :issue:`7491`: :fixture:`tmpdir` and :fixture:`tmp_path` no longer raise an error if the lock to check for
stale temporary directories is not accessible.
- :issue:`7517`: Preserve line endings when captured via ``capfd``.
- :issue:`7534`: Restored the previous formatting of ``TracebackEntry.__str__`` which was changed by accident.
Improved Documentation
----------------------
- :issue:`7422`: Clarified when the ``usefixtures`` mark can apply fixtures to test.
- :issue:`7441`: Add a note about ``-q`` option used in getting started guide.
Trivial/Internal Changes
------------------------
- :issue:`7389`: Fixture scope ``package`` is no longer considered experimental.
pytest 6.0.0rc1 (2020-07-08)
============================
Breaking Changes
----------------
- :issue:`1316`: ``TestReport.longrepr`` is now always an instance of ``ReprExceptionInfo``. Previously it was a ``str`` when a test failed with ``pytest.fail(..., pytrace=False)``.
- :issue:`5965`: symlinks are no longer resolved during collection and matching `conftest.py` files with test file paths.
Resolving symlinks for the current directory and during collection was introduced as a bugfix in 3.9.0, but it actually is a new feature which had unfortunate consequences in Windows and surprising results in other platforms.
The team decided to step back on resolving symlinks at all, planning to review this in the future with a more solid solution (see discussion in
:pull:`6523` for details).
This might break test suites which made use of this feature; the fix is to create a symlink
for the entire test tree, and not only to partial files/tress as it was possible previously.
- :issue:`6505`: ``Testdir.run().parseoutcomes()`` now always returns the parsed nouns in plural form.
Originally ``parseoutcomes()`` would always returns the nouns in plural form, but a change
meant to improve the terminal summary by using singular form single items (``1 warning`` or ``1 error``)
caused an unintended regression by changing the keys returned by ``parseoutcomes()``.
Now the API guarantees to always return the plural form, so calls like this:
.. code-block:: python
result = testdir.runpytest()
result.assert_outcomes(error=1)
Need to be changed to:
.. code-block:: python
result = testdir.runpytest()
result.assert_outcomes(errors=1)
- :issue:`6903`: The ``os.dup()`` function is now assumed to exist. We are not aware of any
supported Python 3 implementations which do not provide it.
- :issue:`7040`: ``-k`` no longer matches against the names of the directories outside the test session root.
Also, ``pytest.Package.name`` is now just the name of the directory containing the package's
``__init__.py`` file, instead of the full path. This is consistent with how the other nodes
are named, and also one of the reasons why ``-k`` would match against any directory containing
the test suite.
- :issue:`7122`: Expressions given to the ``-m`` and ``-k`` options are no longer evaluated using Python's :func:`eval`.
The format supports ``or``, ``and``, ``not``, parenthesis and general identifiers to match against.
Python constants, keywords or other operators are no longer evaluated differently.
- :issue:`7135`: Pytest now uses its own ``TerminalWriter`` class instead of using the one from the ``py`` library.
Plugins generally access this class through ``TerminalReporter.writer``, ``TerminalReporter.write()``
(and similar methods), or ``_pytest.config.create_terminal_writer()``.
The following breaking changes were made:
- Output (``write()`` method and others) no longer flush implicitly; the flushing behavior
of the underlying file is respected. To flush explicitly (for example, if you
want output to be shown before an end-of-line is printed), use ``write(flush=True)`` or
``terminal_writer.flush()``.
- Explicit Windows console support was removed, delegated to the colorama library.
- Support for writing ``bytes`` was removed.
- The ``reline`` method and ``chars_on_current_line`` property were removed.
- The ``stringio`` and ``encoding`` arguments was removed.
- Support for passing a callable instead of a file was removed.
- :issue:`7224`: The `item.catch_log_handler` and `item.catch_log_handlers` attributes, set by the
logging plugin and never meant to be public, are no longer available.
The deprecated ``--no-print-logs`` option and ``log_print`` ini option are removed. Use ``--show-capture`` instead.
- :issue:`7226`: Removed the unused ``args`` parameter from ``pytest.Function.__init__``.
- :issue:`7418`: Removed the `pytest_doctest_prepare_content` hook specification. This hook
hasn't been triggered by pytest for at least 10 years.
- :issue:`7438`: Some changes were made to the internal ``_pytest._code.source``, listed here
for the benefit of plugin authors who may be using it:
- The ``deindent`` argument to ``Source()`` has been removed, now it is always true.
- Support for zero or multiple arguments to ``Source()`` has been removed.
- Support for comparing ``Source`` with an ``str`` has been removed.
- The methods ``Source.isparseable()`` and ``Source.putaround()`` have been removed.
- The method ``Source.compile()`` and function ``_pytest._code.compile()`` have
been removed; use plain ``compile()`` instead.
- The function ``_pytest._code.source.getsource()`` has been removed; use
``Source()`` directly instead.
Deprecations
------------
- :issue:`7210`: The special ``-k '-expr'`` syntax to ``-k`` is deprecated. Use ``-k 'not expr'``
instead.
The special ``-k 'expr:'`` syntax to ``-k`` is deprecated. Please open an issue
if you use this and want a replacement.
- :issue:`4049`: ``pytest_warning_captured`` is deprecated in favor of the ``pytest_warning_recorded`` hook.
Features
--------
- :issue:`1556`: pytest now supports ``pyproject.toml`` files for configuration.
The configuration options is similar to the one available in other formats, but must be defined
in a ``[tool.pytest.ini_options]`` table to be picked up by pytest:
.. code-block:: toml
# pyproject.toml
[tool.pytest.ini_options]
minversion = "6.0"
addopts = "-ra -q"
testpaths = [
"tests",
"integration",
]
More information can be found :ref:`in the docs `.
- :issue:`3342`: pytest now includes inline type annotations and exposes them to user programs.
Most of the user-facing API is covered, as well as internal code.
If you are running a type checker such as mypy on your tests, you may start
noticing type errors indicating incorrect usage. If you run into an error that
you believe to be incorrect, please let us know in an issue.
The types were developed against mypy version 0.780. Versions before 0.750
are known not to work. We recommend using the latest version. Other type
checkers may work as well, but they are not officially verified to work by
pytest yet.
- :issue:`4049`: Introduced a new hook named `pytest_warning_recorded` to convey information about warnings captured by the internal `pytest` warnings plugin.
This hook is meant to replace `pytest_warning_captured`, which is deprecated and will be removed in a future release.
- :issue:`6471`: New command-line flags:
* `--no-header`: disables the initial header, including platform, version, and plugins.
* `--no-summary`: disables the final test summary, including warnings.
- :issue:`6856`: A warning is now shown when an unknown key is read from a config INI file.
The `--strict-config` flag has been added to treat these warnings as errors.
- :issue:`6906`: Added `--code-highlight` command line option to enable/disable code highlighting in terminal output.
- :issue:`7245`: New ``--import-mode=importlib`` option that uses :mod:`importlib` to import test modules.
Traditionally pytest used ``__import__`` while changing ``sys.path`` to import test modules (which
also changes ``sys.modules`` as a side-effect), which works but has a number of drawbacks, like requiring test modules
that don't live in packages to have unique names (as they need to reside under a unique name in ``sys.modules``).
``--import-mode=importlib`` uses more fine grained import mechanisms from ``importlib`` which don't
require pytest to change ``sys.path`` or ``sys.modules`` at all, eliminating much of the drawbacks
of the previous mode.
We intend to make ``--import-mode=importlib`` the default in future versions, so users are encouraged
to try the new mode and provide feedback (both positive or negative) in issue :issue:`7245`.
You can read more about this option in :std:ref:`the documentation `.
- :issue:`7305`: New ``required_plugins`` configuration option allows the user to specify a list of plugins, including version information, that are required for pytest to run. An error is raised if any required plugins are not found when running pytest.
Improvements
------------
- :issue:`4375`: The ``pytest`` command now suppresses the ``BrokenPipeError`` error message that
is printed to stderr when the output of ``pytest`` is piped and and the pipe is
closed by the piped-to program (common examples are ``less`` and ``head``).
- :issue:`4391`: Improved precision of test durations measurement. ``CallInfo`` items now have a new ``.duration`` attribute, created using ``time.perf_counter()``. This attribute is used to fill the ``.duration`` attribute, which is more accurate than the previous ``.stop - .start`` (as these are based on ``time.time()``).
- :issue:`4675`: Rich comparison for dataclasses and `attrs`-classes is now recursive.
- :issue:`6285`: Exposed the `pytest.FixtureLookupError` exception which is raised by `request.getfixturevalue()`
(where `request` is a `FixtureRequest` fixture) when a fixture with the given name cannot be returned.
- :issue:`6433`: If an error is encountered while formatting the message in a logging call, for
example ``logging.warning("oh no!: %s: %s", "first")`` (a second argument is
missing), pytest now propagates the error, likely causing the test to fail.
Previously, such a mistake would cause an error to be printed to stderr, which
is not displayed by default for passing tests. This change makes the mistake
visible during testing.
You may suppress this behavior temporarily or permanently by setting
``logging.raiseExceptions = False``.
- :issue:`6817`: Explicit new-lines in help texts of command-line options are preserved, allowing plugins better control
of the help displayed to users.
- :issue:`6940`: When using the ``--duration`` option, the terminal message output is now more precise about the number and duration of hidden items.
- :issue:`6991`: Collected files are displayed after any reports from hooks, e.g. the status from ``--lf``.
- :issue:`7091`: When ``fd`` capturing is used, through ``--capture=fd`` or the ``capfd`` and
``capfdbinary`` fixtures, and the file descriptor (0, 1, 2) cannot be
duplicated, FD capturing is still performed. Previously, direct writes to the
file descriptors would fail or be lost in this case.
- :issue:`7119`: Exit with an error if the ``--basetemp`` argument is empty, is the current working directory or is one of the parent directories.
This is done to protect against accidental data loss, as any directory passed to this argument is cleared.
- :issue:`7128`: `pytest --version` now displays just the pytest version, while `pytest --version --version` displays more verbose information including plugins. This is more consistent with how other tools show `--version`.
- :issue:`7133`: :meth:`caplog.set_level() <_pytest.logging.LogCaptureFixture.set_level>` will now override any :confval:`log_level` set via the CLI or configuration file.
- :issue:`7159`: :meth:`caplog.set_level() <_pytest.logging.LogCaptureFixture.set_level>` and :meth:`caplog.at_level() <_pytest.logging.LogCaptureFixture.at_level>` no longer affect
the level of logs that are shown in the *Captured log report* report section.
- :issue:`7348`: Improve recursive diff report for comparison asserts on dataclasses / attrs.
- :issue:`7385`: ``--junitxml`` now includes the exception cause in the ``message`` XML attribute for failures during setup and teardown.
Previously:
.. code-block:: xml
Now:
.. code-block:: xml
Bug Fixes
---------
- :issue:`1120`: Fix issue where directories from :fixture:`tmpdir` are not removed properly when multiple instances of pytest are running in parallel.
- :issue:`4583`: Prevent crashing and provide a user-friendly error when a marker expression (`-m`) invoking of :func:`eval` raises any exception.
- :issue:`4677`: The path shown in the summary report for SKIPPED tests is now always relative. Previously it was sometimes absolute.
- :issue:`5456`: Fix a possible race condition when trying to remove lock files used to control access to folders
created by :fixture:`tmp_path` and :fixture:`tmpdir`.
- :issue:`6240`: Fixes an issue where logging during collection step caused duplication of log
messages to stderr.
- :issue:`6428`: Paths appearing in error messages are now correct in case the current working directory has
changed since the start of the session.
- :issue:`6755`: Support deleting paths longer than 260 characters on windows created inside :fixture:`tmpdir`.
- :issue:`6871`: Fix crash with captured output when using :fixture:`capsysbinary`.
- :issue:`6909`: Revert the change introduced by :pull:`6330`, which required all arguments to ``@pytest.mark.parametrize`` to be explicitly defined in the function signature.
The intention of the original change was to remove what was expected to be an unintended/surprising behavior, but it turns out many people relied on it, so the restriction has been reverted.
- :issue:`6910`: Fix crash when plugins return an unknown stats while using the ``--reportlog`` option.
- :issue:`6924`: Ensure a ``unittest.IsolatedAsyncioTestCase`` is actually awaited.
- :issue:`6925`: Fix `TerminalRepr` instances to be hashable again.
- :issue:`6947`: Fix regression where functions registered with :meth:`unittest.TestCase.addCleanup` were not being called on test failures.
- :issue:`6951`: Allow users to still set the deprecated ``TerminalReporter.writer`` attribute.
- :issue:`6956`: Prevent pytest from printing `ConftestImportFailure` traceback to stdout.
- :issue:`6991`: Fix regressions with `--lf` filtering too much since pytest 5.4.
- :issue:`6992`: Revert "tmpdir: clean up indirection via config for factories" :issue:`6767` as it breaks pytest-xdist.
- :issue:`7061`: When a yielding fixture fails to yield a value, report a test setup error instead of crashing.
- :issue:`7076`: The path of file skipped by ``@pytest.mark.skip`` in the SKIPPED report is now relative to invocation directory. Previously it was relative to root directory.
- :issue:`7110`: Fixed regression: ``asyncbase.TestCase`` tests are executed correctly again.
- :issue:`7126`: ``--setup-show`` now doesn't raise an error when a bytes value is used as a ``parametrize``
parameter when Python is called with the ``-bb`` flag.
- :issue:`7143`: Fix :meth:`pytest.File.from_parent` so it forwards extra keyword arguments to the constructor.
- :issue:`7145`: Classes with broken ``__getattribute__`` methods are displayed correctly during failures.
- :issue:`7150`: Prevent hiding the underlying exception when ``ConfTestImportFailure`` is raised.
- :issue:`7180`: Fix ``_is_setup_py`` for files encoded differently than locale.
- :issue:`7215`: Fix regression where running with ``--pdb`` would call :meth:`unittest.TestCase.tearDown` for skipped tests.
- :issue:`7253`: When using ``pytest.fixture`` on a function directly, as in ``pytest.fixture(func)``,
if the ``autouse`` or ``params`` arguments are also passed, the function is no longer
ignored, but is marked as a fixture.
- :issue:`7360`: Fix possibly incorrect evaluation of string expressions passed to ``pytest.mark.skipif`` and ``pytest.mark.xfail``,
in rare circumstances where the exact same string is used but refers to different global values.
- :issue:`7383`: Fixed exception causes all over the codebase, i.e. use `raise new_exception from old_exception` when wrapping an exception.
Improved Documentation
----------------------
- :issue:`7202`: The development guide now links to the contributing section of the docs and `RELEASING.rst` on GitHub.
- :issue:`7233`: Add a note about ``--strict`` and ``--strict-markers`` and the preference for the latter one.
- :issue:`7345`: Explain indirect parametrization and markers for fixtures.
Trivial/Internal Changes
------------------------
- :issue:`7035`: The ``originalname`` attribute of ``_pytest.python.Function`` now defaults to ``name`` if not
provided explicitly, and is always set.
- :issue:`7264`: The dependency on the ``wcwidth`` package has been removed.
- :issue:`7291`: Replaced ``py.iniconfig`` with :pypi:`iniconfig`.
- :issue:`7295`: ``src/_pytest/config/__init__.py`` now uses the ``warnings`` module to report warnings instead of ``sys.stderr.write``.
- :issue:`7356`: Remove last internal uses of deprecated *slave* term from old ``pytest-xdist``.
- :issue:`7357`: ``py``>=1.8.2 is now required.
pytest 5.4.3 (2020-06-02)
=========================
Bug Fixes
---------
- :issue:`6428`: Paths appearing in error messages are now correct in case the current working directory has
changed since the start of the session.
- :issue:`6755`: Support deleting paths longer than 260 characters on windows created inside tmpdir.
- :issue:`6956`: Prevent pytest from printing ConftestImportFailure traceback to stdout.
- :issue:`7150`: Prevent hiding the underlying exception when ``ConfTestImportFailure`` is raised.
- :issue:`7215`: Fix regression where running with ``--pdb`` would call the ``tearDown`` methods of ``unittest.TestCase``
subclasses for skipped tests.
pytest 5.4.2 (2020-05-08)
=========================
Bug Fixes
---------
- :issue:`6871`: Fix crash with captured output when using the :fixture:`capsysbinary fixture `.
- :issue:`6924`: Ensure a ``unittest.IsolatedAsyncioTestCase`` is actually awaited.
- :issue:`6925`: Fix TerminalRepr instances to be hashable again.
- :issue:`6947`: Fix regression where functions registered with ``TestCase.addCleanup`` were not being called on test failures.
- :issue:`6951`: Allow users to still set the deprecated ``TerminalReporter.writer`` attribute.
- :issue:`6992`: Revert "tmpdir: clean up indirection via config for factories" #6767 as it breaks pytest-xdist.
- :issue:`7110`: Fixed regression: ``asyncbase.TestCase`` tests are executed correctly again.
- :issue:`7143`: Fix ``File.from_parent`` so it forwards extra keyword arguments to the constructor.
- :issue:`7145`: Classes with broken ``__getattribute__`` methods are displayed correctly during failures.
- :issue:`7180`: Fix ``_is_setup_py`` for files encoded differently than locale.
pytest 5.4.1 (2020-03-13)
=========================
Bug Fixes
---------
- :issue:`6909`: Revert the change introduced by :pull:`6330`, which required all arguments to ``@pytest.mark.parametrize`` to be explicitly defined in the function signature.
The intention of the original change was to remove what was expected to be an unintended/surprising behavior, but it turns out many people relied on it, so the restriction has been reverted.
- :issue:`6910`: Fix crash when plugins return an unknown stats while using the ``--reportlog`` option.
pytest 5.4.0 (2020-03-12)
=========================
Breaking Changes
----------------
- :issue:`6316`: Matching of ``-k EXPRESSION`` to test names is now case-insensitive.
- :issue:`6443`: Plugins specified with ``-p`` are now loaded after internal plugins, which results in their hooks being called *before* the internal ones.
This makes the ``-p`` behavior consistent with ``PYTEST_PLUGINS``.
- :issue:`6637`: Removed the long-deprecated ``pytest_itemstart`` hook.
This hook has been marked as deprecated and not been even called by pytest for over 10 years now.
- :issue:`6673`: Reversed / fix meaning of "+/-" in error diffs. "-" means that sth. expected is missing in the result and "+" means that there are unexpected extras in the result.
- :issue:`6737`: The ``cached_result`` attribute of ``FixtureDef`` is now set to ``None`` when
the result is unavailable, instead of being deleted.
If your plugin performs checks like ``hasattr(fixturedef, 'cached_result')``,
for example in a ``pytest_fixture_post_finalizer`` hook implementation, replace
it with ``fixturedef.cached_result is not None``. If you ``del`` the attribute,
set it to ``None`` instead.
Deprecations
------------
- :issue:`3238`: Option ``--no-print-logs`` is deprecated and meant to be removed in a future release. If you use ``--no-print-logs``, please try out ``--show-capture`` and
provide feedback.
``--show-capture`` command-line option was added in ``pytest 3.5.0`` and allows to specify how to
display captured output when tests fail: ``no``, ``stdout``, ``stderr``, ``log`` or ``all`` (the default).
- :issue:`571`: Deprecate the unused/broken `pytest_collect_directory` hook.
It was misaligned since the removal of the ``Directory`` collector in 2010
and incorrect/unusable as soon as collection was split from test execution.
- :issue:`5975`: Deprecate using direct constructors for ``Nodes``.
Instead they are now constructed via ``Node.from_parent``.
This transitional mechanism enables us to untangle the very intensely
entangled ``Node`` relationships by enforcing more controlled creation/configuration patterns.
As part of this change, session/config are already disallowed parameters and as we work on the details we might need disallow a few more as well.
Subclasses are expected to use `super().from_parent` if they intend to expand the creation of `Nodes`.
- :issue:`6779`: The ``TerminalReporter.writer`` attribute has been deprecated and should no longer be used. This
was inadvertently exposed as part of the public API of that plugin and ties it too much
with ``py.io.TerminalWriter``.
Features
--------
- :issue:`4597`: New :ref:`--capture=tee-sys ` option to allow both live printing and capturing of test output.
- :issue:`5712`: Now all arguments to ``@pytest.mark.parametrize`` need to be explicitly declared in the function signature or via ``indirect``.
Previously it was possible to omit an argument if a fixture with the same name existed, which was just an accident of implementation and was not meant to be a part of the API.
- :issue:`6454`: Changed default for `-r` to `fE`, which displays failures and errors in the :ref:`short test summary `. `-rN` can be used to disable it (the old behavior).
- :issue:`6469`: New options have been added to the :confval:`junit_logging` option: ``log``, ``out-err``, and ``all``.
- :issue:`6834`: Excess warning summaries are now collapsed per file to ensure readable display of warning summaries.
Improvements
------------
- :issue:`1857`: ``pytest.mark.parametrize`` accepts integers for ``ids`` again, converting it to strings.
- :issue:`449`: Use "yellow" main color with any XPASSED tests.
- :issue:`4639`: Revert "A warning is now issued when assertions are made for ``None``".
The warning proved to be less useful than initially expected and had quite a
few false positive cases.
- :issue:`5686`: ``tmpdir_factory.mktemp`` now fails when given absolute and non-normalized paths.
- :issue:`5984`: The ``pytest_warning_captured`` hook now receives a ``location`` parameter with the code location that generated the warning.
- :issue:`6213`: pytester: the ``testdir`` fixture respects environment settings from the ``monkeypatch`` fixture for inner runs.
- :issue:`6247`: ``--fulltrace`` is honored with collection errors.
- :issue:`6384`: Make `--showlocals` work also with `--tb=short`.
- :issue:`6653`: Add support for matching lines consecutively with :attr:`LineMatcher <_pytest.pytester.LineMatcher>`'s :func:`~_pytest.pytester.LineMatcher.fnmatch_lines` and :func:`~_pytest.pytester.LineMatcher.re_match_lines`.
- :issue:`6658`: Code is now highlighted in tracebacks when ``pygments`` is installed.
Users are encouraged to install ``pygments`` into their environment and provide feedback, because
the plan is to make ``pygments`` a regular dependency in the future.
- :issue:`6795`: Import usage error message with invalid `-o` option.
- :issue:`759`: ``pytest.mark.parametrize`` supports iterators and generators for ``ids``.
Bug Fixes
---------
- :issue:`310`: Add support for calling `pytest.xfail()` and `pytest.importorskip()` with doctests.
- :issue:`3823`: ``--trace`` now works with unittests.
- :issue:`4445`: Fixed some warning reports produced by pytest to point to the correct location of the warning in the user's code.
- :issue:`5301`: Fix ``--last-failed`` to collect new tests from files with known failures.
- :issue:`5928`: Report ``PytestUnknownMarkWarning`` at the level of the user's code, not ``pytest``'s.
- :issue:`5991`: Fix interaction with ``--pdb`` and unittests: do not use unittest's ``TestCase.debug()``.
- :issue:`6334`: Fix summary entries appearing twice when ``f/F`` and ``s/S`` report chars were used at the same time in the ``-r`` command-line option (for example ``-rFf``).
The upper case variants were never documented and the preferred form should be the lower case.
- :issue:`6409`: Fallback to green (instead of yellow) for non-last items without previous passes with colored terminal progress indicator.
- :issue:`6454`: `--disable-warnings` is honored with `-ra` and `-rA`.
- :issue:`6497`: Fix bug in the comparison of request key with cached key in fixture.
A construct ``if key == cached_key:`` can fail either because ``==`` is explicitly disallowed, or for, e.g., NumPy arrays, where the result of ``a == b`` cannot generally be converted to :class:`bool`.
The implemented fix replaces `==` with ``is``.
- :issue:`6557`: Make capture output streams ``.write()`` method return the same return value from original streams.
- :issue:`6566`: Fix ``EncodedFile.writelines`` to call the underlying buffer's ``writelines`` method.
- :issue:`6575`: Fix internal crash when ``faulthandler`` starts initialized
(for example with ``PYTHONFAULTHANDLER=1`` environment variable set) and ``faulthandler_timeout`` defined
in the configuration file.
- :issue:`6597`: Fix node ids which contain a parametrized empty-string variable.
- :issue:`6646`: Assertion rewriting hooks are (re)stored for the current item, which fixes them being still used after e.g. pytester's :func:`testdir.runpytest <_pytest.pytester.Testdir.runpytest>` etc.
- :issue:`6660`: :py:func:`pytest.exit` is handled when emitted from the :hook:`pytest_sessionfinish` hook. This includes quitting from a debugger.
- :issue:`6752`: When :py:func:`pytest.raises` is used as a function (as opposed to a context manager),
a `match` keyword argument is now passed through to the tested function. Previously
it was swallowed and ignored (regression in pytest 5.1.0).
- :issue:`6801`: Do not display empty lines in between traceback for unexpected exceptions with doctests.
- :issue:`6802`: The :fixture:`testdir fixture ` works within doctests now.
Improved Documentation
----------------------
- :issue:`6696`: Add list of fixtures to start of fixture chapter.
- :issue:`6742`: Expand first sentence on fixtures into a paragraph.
Trivial/Internal Changes
------------------------
- :issue:`6404`: Remove usage of ``parser`` module, deprecated in Python 3.9.
pytest 5.3.5 (2020-01-29)
=========================
Bug Fixes
---------
- :issue:`6517`: Fix regression in pytest 5.3.4 causing an INTERNALERROR due to a wrong assertion.
pytest 5.3.4 (2020-01-20)
=========================
Bug Fixes
---------
- :issue:`6496`: Revert :issue:`6436`: unfortunately this change has caused a number of regressions in many suites,
so the team decided to revert this change and make a new release while we continue to look for a solution.
pytest 5.3.3 (2020-01-16)
=========================
Bug Fixes
---------
- :issue:`2780`: Captured output during teardown is shown with ``-rP``.
- :issue:`5971`: Fix a ``pytest-xdist`` crash when dealing with exceptions raised in subprocesses created by the
``multiprocessing`` module.
- :issue:`6436`: :class:`FixtureDef <_pytest.fixtures.FixtureDef>` objects now properly register their finalizers with autouse and
parameterized fixtures that execute before them in the fixture stack so they are torn
down at the right times, and in the right order.
- :issue:`6532`: Fix parsing of outcomes containing multiple errors with ``testdir`` results (regression in 5.3.0).
Trivial/Internal Changes
------------------------
- :issue:`6350`: Optimized automatic renaming of test parameter IDs.
pytest 5.3.2 (2019-12-13)
=========================
Improvements
------------
- :issue:`4639`: Revert "A warning is now issued when assertions are made for ``None``".
The warning proved to be less useful than initially expected and had quite a
few false positive cases.
Bug Fixes
---------
- :issue:`5430`: junitxml: Logs for failed test are now passed to junit report in case the test fails during call phase.
- :issue:`6290`: The supporting files in the ``.pytest_cache`` directory are kept with ``--cache-clear``, which only clears cached values now.
- :issue:`6301`: Fix assertion rewriting for egg-based distributions and ``editable`` installs (``pip install --editable``).
pytest 5.3.1 (2019-11-25)
=========================
Improvements
------------
- :issue:`6231`: Improve check for misspelling of :ref:`pytest.mark.parametrize ref`.
- :issue:`6257`: Handle :func:`pytest.exit` being used via :hook:`pytest_internalerror`, e.g. when quitting pdb from post mortem.
Bug Fixes
---------
- :issue:`5914`: pytester: fix :py:func:`~_pytest.pytester.LineMatcher.no_fnmatch_line` when used after positive matching.
- :issue:`6082`: Fix line detection for doctest samples inside :py:class:`python:property` docstrings, as a workaround to :bpo:`17446`.
- :issue:`6254`: Fix compatibility with pytest-parallel (regression in pytest 5.3.0).
- :issue:`6255`: Clear the :py:data:`sys.last_traceback`, :py:data:`sys.last_type`
and :py:data:`sys.last_value` attributes by deleting them instead
of setting them to ``None``. This better matches the behaviour of
the Python standard library.
pytest 5.3.0 (2019-11-19)
=========================
Deprecations
------------
- :issue:`6179`: The default value of :confval:`junit_family` option will change to ``"xunit2"`` in pytest 6.0, given
that this is the version supported by default in modern tools that manipulate this type of file.
In order to smooth the transition, pytest will issue a warning in case the ``--junitxml`` option
is given in the command line but :confval:`junit_family` is not explicitly configured in ``pytest.ini``.
For more information, :ref:`see the docs `.
Features
--------
- :issue:`4488`: The pytest team has created the `pytest-reportlog `__
plugin, which provides a new ``--report-log=FILE`` option that writes *report logs* into a file as the test session executes.
Each line of the report log contains a self contained JSON object corresponding to a testing event,
such as a collection or a test result report. The file is guaranteed to be flushed after writing
each line, so systems can read and process events in real-time.
The plugin is meant to replace the ``--resultlog`` option, which is deprecated and meant to be removed
in a future release. If you use ``--resultlog``, please try out ``pytest-reportlog`` and
provide feedback.
- :issue:`4730`: When :py:data:`sys.pycache_prefix` (Python 3.8+) is set, it will be used by pytest to cache test files changed by the assertion rewriting mechanism.
This makes it easier to benefit of cached ``.pyc`` files even on file systems without permissions.
- :issue:`5515`: Allow selective auto-indentation of multiline log messages.
Adds command line option ``--log-auto-indent``, config option
:confval:`log_auto_indent` and support for per-entry configuration of
indentation behavior on calls to :py:func:`python:logging.log()`.
Alters the default for auto-indention from ``"on"`` to ``"off"``. This
restores the older behavior that existed prior to v4.6.0. This
reversion to earlier behavior was done because it is better to
activate new features that may lead to broken tests explicitly
rather than implicitly.
- :issue:`5914`: :fixture:`testdir` learned two new functions, :py:func:`~_pytest.pytester.LineMatcher.no_fnmatch_line` and
:py:func:`~_pytest.pytester.LineMatcher.no_re_match_line`.
The functions are used to ensure the captured text *does not* match the given
pattern.
The previous idiom was to use :py:func:`python:re.match`:
.. code-block:: python
result = testdir.runpytest()
assert re.match(pat, result.stdout.str()) is None
Or the ``in`` operator:
.. code-block:: python
result = testdir.runpytest()
assert text in result.stdout.str()
But the new functions produce best output on failure.
- :issue:`6057`: Added tolerances to complex values when printing ``pytest.approx``.
For example, ``repr(pytest.approx(3+4j))`` returns ``(3+4j) ± 5e-06 ∠±180°``. This is polar notation indicating a circle around the expected value, with a radius of 5e-06. For ``approx`` comparisons to return ``True``, the actual value should fall within this circle.
- :issue:`6061`: Added the pluginmanager as an argument to ``pytest_addoption``
so that hooks can be invoked when setting up command line options. This is
useful for having one plugin communicate things to another plugin,
such as default values or which set of command line options to add.
Improvements
------------
- :issue:`5061`: Use multiple colors with terminal summary statistics.
- :issue:`5630`: Quitting from debuggers is now properly handled in ``doctest`` items.
- :issue:`5924`: Improved verbose diff output with sequences.
Before:
::
E AssertionError: assert ['version', '...version_info'] == ['version', '...version', ...]
E Right contains 3 more items, first extra item: ' '
E Full diff:
E - ['version', 'version_info', 'sys.version', 'sys.version_info']
E + ['version',
E + 'version_info',
E + 'sys.version',
E + 'sys.version_info',
E + ' ',
E + 'sys.version',
E + 'sys.version_info']
After:
::
E AssertionError: assert ['version', '...version_info'] == ['version', '...version', ...]
E Right contains 3 more items, first extra item: ' '
E Full diff:
E [
E 'version',
E 'version_info',
E 'sys.version',
E 'sys.version_info',
E + ' ',
E + 'sys.version',
E + 'sys.version_info',
E ]
- :issue:`5934`: ``repr`` of ``ExceptionInfo`` objects has been improved to honor the ``__repr__`` method of the underlying exception.
- :issue:`5936`: Display untruncated assertion message with ``-vv``.
- :issue:`5990`: Fixed plurality mismatch in test summary (e.g. display "1 error" instead of "1 errors").
- :issue:`6008`: ``Config.InvocationParams.args`` is now always a ``tuple`` to better convey that it should be
immutable and avoid accidental modifications.
- :issue:`6023`: ``pytest.main`` returns a ``pytest.ExitCode`` instance now, except for when custom exit codes are used (where it returns ``int`` then still).
- :issue:`6026`: Align prefixes in output of pytester's ``LineMatcher``.
- :issue:`6059`: Collection errors are reported as errors (and not failures like before) in the terminal's short test summary.
- :issue:`6069`: ``pytester.spawn`` does not skip/xfail tests on FreeBSD anymore unconditionally.
- :issue:`6097`: The "[...%]" indicator in the test summary is now colored according to the final (new) multi-colored line's main color.
- :issue:`6116`: Added ``--co`` as a synonym to ``--collect-only``.
- :issue:`6148`: ``atomicwrites`` is now only used on Windows, fixing a performance regression with assertion rewriting on Unix.
- :issue:`6152`: Now parametrization will use the ``__name__`` attribute of any object for the id, if present. Previously it would only use ``__name__`` for functions and classes.
- :issue:`6176`: Improved failure reporting with pytester's ``Hookrecorder.assertoutcome``.
- :issue:`6181`: The reason for a stopped session, e.g. with ``--maxfail`` / ``-x``, now gets reported in the test summary.
- :issue:`6206`: Improved ``cache.set`` robustness and performance.
Bug Fixes
---------
- :issue:`2049`: Fixed ``--setup-plan`` showing inaccurate information about fixture lifetimes.
- :issue:`2548`: Fixed line offset mismatch of skipped tests in terminal summary.
- :issue:`6039`: The ``PytestDoctestRunner`` is now properly invalidated when unconfiguring the doctest plugin.
This is important when used with ``pytester``'s ``runpytest_inprocess``.
- :issue:`6047`: BaseExceptions are now handled in ``saferepr``, which includes ``pytest.fail.Exception`` etc.
- :issue:`6074`: pytester: fixed order of arguments in ``rm_rf`` warning when cleaning up temporary directories, and do not emit warnings for errors with ``os.open``.
- :issue:`6189`: Fixed result of ``getmodpath`` method.
Trivial/Internal Changes
------------------------
- :issue:`4901`: ``RunResult`` from ``pytester`` now displays the mnemonic of the ``ret`` attribute when it is a
valid ``pytest.ExitCode`` value.
pytest 5.2.4 (2019-11-15)
=========================
Bug Fixes
---------
- :issue:`6194`: Fix incorrect discovery of non-test ``__init__.py`` files.
- :issue:`6197`: Revert "The first test in a package (``__init__.py``) marked with ``@pytest.mark.skip`` is now correctly skipped.".
pytest 5.2.3 (2019-11-14)
=========================
Bug Fixes
---------
- :issue:`5830`: The first test in a package (``__init__.py``) marked with ``@pytest.mark.skip`` is now correctly skipped.
- :issue:`6099`: Fix ``--trace`` when used with parametrized functions.
- :issue:`6183`: Using ``request`` as a parameter name in ``@pytest.mark.parametrize`` now produces a more
user-friendly error.
pytest 5.2.2 (2019-10-24)
=========================
Bug Fixes
---------
- :issue:`5206`: Fix ``--nf`` to not forget about known nodeids with partial test selection.
- :issue:`5906`: Fix crash with ``KeyboardInterrupt`` during ``--setup-show``.
- :issue:`5946`: Fixed issue when parametrizing fixtures with numpy arrays (and possibly other sequence-like types).
- :issue:`6044`: Properly ignore ``FileNotFoundError`` exceptions when trying to remove old temporary directories,
for instance when multiple processes try to remove the same directory (common with ``pytest-xdist``
for example).
pytest 5.2.1 (2019-10-06)
=========================
Bug Fixes
---------
- :issue:`5902`: Fix warnings about deprecated ``cmp`` attribute in ``attrs>=19.2``.
pytest 5.2.0 (2019-09-28)
=========================
Deprecations
------------
- :issue:`1682`: Passing arguments to pytest.fixture() as positional arguments is deprecated - pass them
as a keyword argument instead.
Features
--------
- :issue:`1682`: The ``scope`` parameter of ``@pytest.fixture`` can now be a callable that receives
the fixture name and the ``config`` object as keyword-only parameters.
See :ref:`the docs ` for more information.
- :issue:`5764`: New behavior of the ``--pastebin`` option: failures to connect to the pastebin server are reported, without failing the pytest run
Bug Fixes
---------
- :issue:`5806`: Fix "lexer" being used when uploading to bpaste.net from ``--pastebin`` to "text".
- :issue:`5884`: Fix ``--setup-only`` and ``--setup-show`` for custom pytest items.
Trivial/Internal Changes
------------------------
- :issue:`5056`: The HelpFormatter uses ``py.io.get_terminal_width`` for better width detection.
pytest 5.1.3 (2019-09-18)
=========================
Bug Fixes
---------
- :issue:`5807`: Fix pypy3.6 (nightly) on windows.
- :issue:`5811`: Handle ``--fulltrace`` correctly with ``pytest.raises``.
- :issue:`5819`: Windows: Fix regression with conftest whose qualified name contains uppercase
characters (introduced by #5792).
pytest 5.1.2 (2019-08-30)
=========================
Bug Fixes
---------
- :issue:`2270`: Fixed ``self`` reference in function-scoped fixtures defined plugin classes: previously ``self``
would be a reference to a *test* class, not the *plugin* class.
- :issue:`570`: Fixed long standing issue where fixture scope was not respected when indirect fixtures were used during
parametrization.
- :issue:`5782`: Fix decoding error when printing an error response from ``--pastebin``.
- :issue:`5786`: Chained exceptions in test and collection reports are now correctly serialized, allowing plugins like
``pytest-xdist`` to display them properly.
- :issue:`5792`: Windows: Fix error that occurs in certain circumstances when loading
``conftest.py`` from a working directory that has casing other than the one stored
in the filesystem (e.g., ``c:\test`` instead of ``C:\test``).
pytest 5.1.1 (2019-08-20)
=========================
Bug Fixes
---------
- :issue:`5751`: Fixed ``TypeError`` when importing pytest on Python 3.5.0 and 3.5.1.
pytest 5.1.0 (2019-08-15)
=========================
Removals
--------
- :issue:`5180`: As per our policy, the following features have been deprecated in the 4.X series and are now
removed:
* ``Request.getfuncargvalue``: use ``Request.getfixturevalue`` instead.
* ``pytest.raises`` and ``pytest.warns`` no longer support strings as the second argument.
* ``message`` parameter of ``pytest.raises``.
* ``pytest.raises``, ``pytest.warns`` and ``ParameterSet.param`` now use native keyword-only
syntax. This might change the exception message from previous versions, but they still raise
``TypeError`` on unknown keyword arguments as before.
* ``pytest.config`` global variable.
* ``tmpdir_factory.ensuretemp`` method.
* ``pytest_logwarning`` hook.
* ``RemovedInPytest4Warning`` warning type.
* ``request`` is now a reserved name for fixtures.
For more information consult :std:doc:`deprecations` in the docs.
- :issue:`5565`: Removed unused support code for :pypi:`unittest2`.
The ``unittest2`` backport module is no longer
necessary since Python 3.3+, and the small amount of code in pytest to support it also doesn't seem
to be used: after removed, all tests still pass unchanged.
Although our policy is to introduce a deprecation period before removing any features or support
for third party libraries, because this code is apparently not used
at all (even if ``unittest2`` is used by a test suite executed by pytest), it was decided to
remove it in this release.
If you experience a regression because of this, please :issue:`file an issue `.
- :issue:`5615`: ``pytest.fail``, ``pytest.xfail`` and ``pytest.skip`` no longer support bytes for the message argument.
This was supported for Python 2 where it was tempting to use ``"message"``
instead of ``u"message"``.
Python 3 code is unlikely to pass ``bytes`` to these functions. If you do,
please decode it to an ``str`` beforehand.
Features
--------
- :issue:`5564`: New ``Config.invocation_args`` attribute containing the unchanged arguments passed to ``pytest.main()``.
- :issue:`5576`: New :ref:`NUMBER `
option for doctests to ignore irrelevant differences in floating-point numbers.
Inspired by Sébastien Boisgérault's `numtest `__
extension for doctest.
Improvements
------------
- :issue:`5471`: JUnit XML now includes a timestamp and hostname in the testsuite tag.
- :issue:`5707`: Time taken to run the test suite now includes a human-readable representation when it takes over
60 seconds, for example::
===== 2 failed in 102.70s (0:01:42) =====
Bug Fixes
---------
- :issue:`4344`: Fix RuntimeError/StopIteration when trying to collect package with "__init__.py" only.
- :issue:`5115`: Warnings issued during ``pytest_configure`` are explicitly not treated as errors, even if configured as such, because it otherwise completely breaks pytest.
- :issue:`5477`: The XML file produced by ``--junitxml`` now correctly contain a ```` root element.
- :issue:`5524`: Fix issue where ``tmp_path`` and ``tmpdir`` would not remove directories containing files marked as read-only,
which could lead to pytest crashing when executed a second time with the ``--basetemp`` option.
- :issue:`5537`: Replace ``importlib_metadata`` backport with ``importlib.metadata`` from the
standard library on Python 3.8+.
- :issue:`5578`: Improve type checking for some exception-raising functions (``pytest.xfail``, ``pytest.skip``, etc)
so they provide better error messages when users meant to use marks (for example ``@pytest.xfail``
instead of ``@pytest.mark.xfail``).
- :issue:`5606`: Fixed internal error when test functions were patched with objects that cannot be compared
for truth values against others, like ``numpy`` arrays.
- :issue:`5634`: ``pytest.exit`` is now correctly handled in ``unittest`` cases.
This makes ``unittest`` cases handle ``quit`` from pytest's pdb correctly.
- :issue:`5650`: Improved output when parsing an ini configuration file fails.
- :issue:`5701`: Fix collection of ``staticmethod`` objects defined with ``functools.partial``.
- :issue:`5734`: Skip async generator test functions, and update the warning message to refer to ``async def`` functions.
Improved Documentation
----------------------
- :issue:`5669`: Add docstring for ``Testdir.copy_example``.
Trivial/Internal Changes
------------------------
- :issue:`5095`: XML files of the ``xunit2`` family are now validated against the schema by pytest's own test suite
to avoid future regressions.
- :issue:`5516`: Cache node splitting function which can improve collection performance in very large test suites.
- :issue:`5603`: Simplified internal ``SafeRepr`` class and removed some dead code.
- :issue:`5664`: When invoking pytest's own testsuite with ``PYTHONDONTWRITEBYTECODE=1``,
the ``test_xfail_handling`` test no longer fails.
- :issue:`5684`: Replace manual handling of ``OSError.errno`` in the codebase by new ``OSError`` subclasses (``PermissionError``, ``FileNotFoundError``, etc.).
pytest 5.0.1 (2019-07-04)
=========================
Bug Fixes
---------
- :issue:`5479`: Improve quoting in ``raises`` match failure message.
- :issue:`5523`: Fixed using multiple short options together in the command-line (for example ``-vs``) in Python 3.8+.
- :issue:`5547`: ``--step-wise`` now handles ``xfail(strict=True)`` markers properly.
Improved Documentation
----------------------
- :issue:`5517`: Improve "Declaring new hooks" section in chapter "Writing Plugins"
pytest 5.0.0 (2019-06-28)
=========================
Important
---------
This release is a Python3.5+ only release.
For more details, see our `Python 2.7 and 3.4 support plan
`_.
Removals
--------
- :issue:`1149`: Pytest no longer accepts prefixes of command-line arguments, for example
typing ``pytest --doctest-mod`` inplace of ``--doctest-modules``.
This was previously allowed where the ``ArgumentParser`` thought it was unambiguous,
but this could be incorrect due to delayed parsing of options for plugins.
See for example issues :issue:`1149`,
:issue:`3413`, and
:issue:`4009`.
- :issue:`5402`: **PytestDeprecationWarning are now errors by default.**
Following our plan to remove deprecated features with as little disruption as
possible, all warnings of type ``PytestDeprecationWarning`` now generate errors
instead of warning messages.
**The affected features will be effectively removed in pytest 5.1**, so please consult the
:std:doc:`deprecations` section in the docs for directions on how to update existing code.
In the pytest ``5.0.X`` series, it is possible to change the errors back into warnings as a stop
gap measure by adding this to your ``pytest.ini`` file:
.. code-block:: ini
[pytest]
filterwarnings =
ignore::pytest.PytestDeprecationWarning
But this will stop working when pytest ``5.1`` is released.
**If you have concerns** about the removal of a specific feature, please add a
comment to :issue:`5402`.
- :issue:`5412`: ``ExceptionInfo`` objects (returned by ``pytest.raises``) now have the same ``str`` representation as ``repr``, which
avoids some confusion when users use ``print(e)`` to inspect the object.
This means code like:
.. code-block:: python
with pytest.raises(SomeException) as e:
...
assert "some message" in str(e)
Needs to be changed to:
.. code-block:: python
with pytest.raises(SomeException) as e:
...
assert "some message" in str(e.value)
Deprecations
------------
- :issue:`4488`: The removal of the ``--result-log`` option and module has been postponed to (tentatively) pytest 6.0 as
the team has not yet got around to implement a good alternative for it.
- :issue:`466`: The ``funcargnames`` attribute has been an alias for ``fixturenames`` since
pytest 2.3, and is now deprecated in code too.
Features
--------
- :issue:`3457`: New :hook:`pytest_assertion_pass`
hook, called with context information when an assertion *passes*.
This hook is still **experimental** so use it with caution.
- :issue:`5440`: The :mod:`faulthandler` standard library
module is now enabled by default to help users diagnose crashes in C modules.
This functionality was provided by integrating the external
`pytest-faulthandler `__ plugin into the core,
so users should remove that plugin from their requirements if used.
For more information see the docs: :ref:`faulthandler`.
- :issue:`5452`: When warnings are configured as errors, pytest warnings now appear as originating from ``pytest.`` instead of the internal ``_pytest.warning_types.`` module.
- :issue:`5125`: ``Session.exitcode`` values are now coded in ``pytest.ExitCode``, an ``IntEnum``. This makes the exit code available for consumer code and are more explicit other than just documentation. User defined exit codes are still valid, but should be used with caution.
The team doesn't expect this change to break test suites or plugins in general, except in esoteric/specific scenarios.
**pytest-xdist** users should upgrade to ``1.29.0`` or later, as ``pytest-xdist`` required a compatibility fix because of this change.
Bug Fixes
---------
- :issue:`1403`: Switch from ``imp`` to ``importlib``.
- :issue:`1671`: The name of the ``.pyc`` files cached by the assertion writer now includes the pytest version
to avoid stale caches.
- :issue:`2761`: Honor :pep:`235` on case-insensitive file systems.
- :issue:`5078`: Test module is no longer double-imported when using ``--pyargs``.
- :issue:`5260`: Improved comparison of byte strings.
When comparing bytes, the assertion message used to show the byte numeric value when showing the differences::
def test():
> assert b'spam' == b'eggs'
E AssertionError: assert b'spam' == b'eggs'
E At index 0 diff: 115 != 101
E Use -v to get the full diff
It now shows the actual ascii representation instead, which is often more useful::
def test():
> assert b'spam' == b'eggs'
E AssertionError: assert b'spam' == b'eggs'
E At index 0 diff: b's' != b'e'
E Use -v to get the full diff
- :issue:`5335`: Colorize level names when the level in the logging format is formatted using
'%(levelname).Xs' (truncated fixed width alignment), where X is an integer.
- :issue:`5354`: Fix ``pytest.mark.parametrize`` when the argvalues is an iterator.
- :issue:`5370`: Revert unrolling of ``all()`` to fix ``NameError`` on nested comprehensions.
- :issue:`5371`: Revert unrolling of ``all()`` to fix incorrect handling of generators with ``if``.
- :issue:`5372`: Revert unrolling of ``all()`` to fix incorrect assertion when using ``all()`` in an expression.
- :issue:`5383`: ``-q`` has again an impact on the style of the collected items
(``--collect-only``) when ``--log-cli-level`` is used.
- :issue:`5389`: Fix regressions of :pull:`5063` for ``importlib_metadata.PathDistribution`` which have their ``files`` attribute being ``None``.
- :issue:`5390`: Fix regression where the ``obj`` attribute of ``TestCase`` items was no longer bound to methods.
- :issue:`5404`: Emit a warning when attempting to unwrap a broken object raises an exception,
for easier debugging (:issue:`5080`).
- :issue:`5432`: Prevent "already imported" warnings from assertion rewriter when invoking pytest in-process multiple times.
- :issue:`5433`: Fix assertion rewriting in packages (``__init__.py``).
- :issue:`5444`: Fix ``--stepwise`` mode when the first file passed on the command-line fails to collect.
- :issue:`5482`: Fix bug introduced in 4.6.0 causing collection errors when passing
more than 2 positional arguments to ``pytest.mark.parametrize``.
- :issue:`5505`: Fix crash when discovery fails while using ``-p no:terminal``.
Improved Documentation
----------------------
- :issue:`5315`: Expand docs on mocking classes and dictionaries with ``monkeypatch``.
- :issue:`5416`: Fix PytestUnknownMarkWarning in run/skip example.
pytest 4.6.11 (2020-06-04)
==========================
Bug Fixes
---------
- :issue:`6334`: Fix summary entries appearing twice when ``f/F`` and ``s/S`` report chars were used at the same time in the ``-r`` command-line option (for example ``-rFf``).
The upper case variants were never documented and the preferred form should be the lower case.
- :issue:`7310`: Fix ``UnboundLocalError: local variable 'letter' referenced before
assignment`` in ``_pytest.terminal.pytest_report_teststatus()``
when plugins return report objects in an unconventional state.
This was making ``pytest_report_teststatus()`` skip
entering if-block branches that declare the ``letter`` variable.
The fix was to set the initial value of the ``letter`` before
the if-block cascade so that it always has a value.
pytest 4.6.10 (2020-05-08)
==========================
Features
--------
- :issue:`6870`: New ``Config.invocation_args`` attribute containing the unchanged arguments passed to ``pytest.main()``.
Remark: while this is technically a new feature and according to our
`policy `_
it should not have been backported, we have opened an exception in this
particular case because it fixes a serious interaction with ``pytest-xdist``,
so it can also be considered a bugfix.
Trivial/Internal Changes
------------------------
- :issue:`6404`: Remove usage of ``parser`` module, deprecated in Python 3.9.
pytest 4.6.9 (2020-01-04)
=========================
Bug Fixes
---------
- :issue:`6301`: Fix assertion rewriting for egg-based distributions and ``editable`` installs (``pip install --editable``).
pytest 4.6.8 (2019-12-19)
=========================
Features
--------
- :issue:`5471`: JUnit XML now includes a timestamp and hostname in the testsuite tag.
Bug Fixes
---------
- :issue:`5430`: junitxml: Logs for failed test are now passed to junit report in case the test fails during call phase.
Trivial/Internal Changes
------------------------
- :issue:`6345`: Pin ``colorama`` to ``0.4.1`` only for Python 3.4 so newer Python versions can still receive colorama updates.
pytest 4.6.7 (2019-12-05)
=========================
Bug Fixes
---------
- :issue:`5477`: The XML file produced by ``--junitxml`` now correctly contain a ```` root element.
- :issue:`6044`: Properly ignore ``FileNotFoundError`` (``OSError.errno == NOENT`` in Python 2) exceptions when trying to remove old temporary directories,
for instance when multiple processes try to remove the same directory (common with ``pytest-xdist``
for example).
pytest 4.6.6 (2019-10-11)
=========================
Bug Fixes
---------
- :issue:`5523`: Fixed using multiple short options together in the command-line (for example ``-vs``) in Python 3.8+.
- :issue:`5537`: Replace ``importlib_metadata`` backport with ``importlib.metadata`` from the
standard library on Python 3.8+.
- :issue:`5806`: Fix "lexer" being used when uploading to bpaste.net from ``--pastebin`` to "text".
- :issue:`5902`: Fix warnings about deprecated ``cmp`` attribute in ``attrs>=19.2``.
Trivial/Internal Changes
------------------------
- :issue:`5801`: Fixes python version checks (detected by ``flake8-2020``) in case python4 becomes a thing.
pytest 4.6.5 (2019-08-05)
=========================
Bug Fixes
---------
- :issue:`4344`: Fix RuntimeError/StopIteration when trying to collect package with "__init__.py" only.
- :issue:`5478`: Fix encode error when using unicode strings in exceptions with ``pytest.raises``.
- :issue:`5524`: Fix issue where ``tmp_path`` and ``tmpdir`` would not remove directories containing files marked as read-only,
which could lead to pytest crashing when executed a second time with the ``--basetemp`` option.
- :issue:`5547`: ``--step-wise`` now handles ``xfail(strict=True)`` markers properly.
- :issue:`5650`: Improved output when parsing an ini configuration file fails.
pytest 4.6.4 (2019-06-28)
=========================
Bug Fixes
---------
- :issue:`5404`: Emit a warning when attempting to unwrap a broken object raises an exception,
for easier debugging (:issue:`5080`).
- :issue:`5444`: Fix ``--stepwise`` mode when the first file passed on the command-line fails to collect.
- :issue:`5482`: Fix bug introduced in 4.6.0 causing collection errors when passing
more than 2 positional arguments to ``pytest.mark.parametrize``.
- :issue:`5505`: Fix crash when discovery fails while using ``-p no:terminal``.
pytest 4.6.3 (2019-06-11)
=========================
Bug Fixes
---------
- :issue:`5383`: ``-q`` has again an impact on the style of the collected items
(``--collect-only``) when ``--log-cli-level`` is used.
- :issue:`5389`: Fix regressions of :pull:`5063` for ``importlib_metadata.PathDistribution`` which have their ``files`` attribute being ``None``.
- :issue:`5390`: Fix regression where the ``obj`` attribute of ``TestCase`` items was no longer bound to methods.
pytest 4.6.2 (2019-06-03)
=========================
Bug Fixes
---------
- :issue:`5370`: Revert unrolling of ``all()`` to fix ``NameError`` on nested comprehensions.
- :issue:`5371`: Revert unrolling of ``all()`` to fix incorrect handling of generators with ``if``.
- :issue:`5372`: Revert unrolling of ``all()`` to fix incorrect assertion when using ``all()`` in an expression.
pytest 4.6.1 (2019-06-02)
=========================
Bug Fixes
---------
- :issue:`5354`: Fix ``pytest.mark.parametrize`` when the argvalues is an iterator.
- :issue:`5358`: Fix assertion rewriting of ``all()`` calls to deal with non-generators.
pytest 4.6.0 (2019-05-31)
=========================
Important
---------
The ``4.6.X`` series will be the last series to support **Python 2 and Python 3.4**.
For more details, see our `Python 2.7 and 3.4 support plan
`_.
Features
--------
- :issue:`4559`: Added the ``junit_log_passing_tests`` ini value which can be used to enable or disable logging of passing test output in the Junit XML file.
- :issue:`4956`: pytester's ``testdir.spawn`` uses ``tmpdir`` as HOME/USERPROFILE directory.
- :issue:`5062`: Unroll calls to ``all`` to full for-loops with assertion rewriting for better failure messages, especially when using Generator Expressions.
- :issue:`5063`: Switch from ``pkg_resources`` to ``importlib-metadata`` for entrypoint detection for improved performance and import time.
- :issue:`5091`: The output for ini options in ``--help`` has been improved.
- :issue:`5269`: ``pytest.importorskip`` includes the ``ImportError`` now in the default ``reason``.
- :issue:`5311`: Captured logs that are output for each failing test are formatted using the
ColoredLevelFormatter.
- :issue:`5312`: Improved formatting of multiline log messages in Python 3.
Bug Fixes
---------
- :issue:`2064`: The debugging plugin imports the wrapped ``Pdb`` class (``--pdbcls``) on-demand now.
- :issue:`4908`: The ``pytest_enter_pdb`` hook gets called with post-mortem (``--pdb``).
- :issue:`5036`: Fix issue where fixtures dependent on other parametrized fixtures would be erroneously parametrized.
- :issue:`5256`: Handle internal error due to a lone surrogate unicode character not being representable in Jython.
- :issue:`5257`: Ensure that ``sys.stdout.mode`` does not include ``'b'`` as it is a text stream.
- :issue:`5278`: Pytest's internal python plugin can be disabled using ``-p no:python`` again.
- :issue:`5286`: Fix issue with ``disable_test_id_escaping_and_forfeit_all_rights_to_community_support`` option not working when using a list of test IDs in parametrized tests.
- :issue:`5330`: Show the test module being collected when emitting ``PytestCollectionWarning`` messages for
test classes with ``__init__`` and ``__new__`` methods to make it easier to pin down the problem.
- :issue:`5333`: Fix regression in 4.5.0 with ``--lf`` not re-running all tests with known failures from non-selected tests.
Improved Documentation
----------------------
- :issue:`5250`: Expand docs on use of ``setenv`` and ``delenv`` with ``monkeypatch``.
pytest 4.5.0 (2019-05-11)
=========================
Features
--------
- :issue:`4826`: A warning is now emitted when unknown marks are used as a decorator.
This is often due to a typo, which can lead to silently broken tests.
- :issue:`4907`: Show XFail reason as part of JUnitXML message field.
- :issue:`5013`: Messages from crash reports are displayed within test summaries now, truncated to the terminal width.
- :issue:`5023`: New flag ``--strict-markers`` that triggers an error when unknown markers (e.g. those not registered using the :confval:`markers` option in the configuration file) are used in the test suite.
The existing ``--strict`` option has the same behavior currently, but can be augmented in the future for additional checks.
- :issue:`5026`: Assertion failure messages for sequences and dicts contain the number of different items now.
- :issue:`5034`: Improve reporting with ``--lf`` and ``--ff`` (run-last-failure).
- :issue:`5035`: The ``--cache-show`` option/action accepts an optional glob to show only matching cache entries.
- :issue:`5059`: Standard input (stdin) can be given to pytester's ``Testdir.run()`` and ``Testdir.popen()``.
- :issue:`5068`: The ``-r`` option learnt about ``A`` to display all reports (including passed ones) in the short test summary.
- :issue:`5108`: The short test summary is displayed after passes with output (``-rP``).
- :issue:`5172`: The ``--last-failed`` (``--lf``) option got smarter and will now skip entire files if all tests
of that test file have passed in previous runs, greatly speeding up collection.
- :issue:`5177`: Introduce new specific warning ``PytestWarning`` subclasses to make it easier to filter warnings based on the class, rather than on the message. The new subclasses are:
* ``PytestAssertRewriteWarning``
* ``PytestCacheWarning``
* ``PytestCollectionWarning``
* ``PytestConfigWarning``
* ``PytestUnhandledCoroutineWarning``
* ``PytestUnknownMarkWarning``
- :issue:`5202`: New ``record_testsuite_property`` session-scoped fixture allows users to log ```` tags at the ``testsuite``
level with the ``junitxml`` plugin.
The generated XML is compatible with the latest xunit standard, contrary to
the properties recorded by ``record_property`` and ``record_xml_attribute``.
- :issue:`5214`: The default logging format has been changed to improve readability. Here is an
example of a previous logging message::
test_log_cli_enabled_disabled.py 3 CRITICAL critical message logged by test
This has now become::
CRITICAL root:test_log_cli_enabled_disabled.py:3 critical message logged by test
The formatting can be changed through the :confval:`log_format` configuration option.
- :issue:`5220`: ``--fixtures`` now also shows fixture scope for scopes other than ``"function"``.
Bug Fixes
---------
- :issue:`5113`: Deselected items from plugins using ``pytest_collect_modifyitems`` as a hookwrapper are correctly reported now.
- :issue:`5144`: With usage errors ``exitstatus`` is set to ``EXIT_USAGEERROR`` in the ``pytest_sessionfinish`` hook now as expected.
- :issue:`5235`: ``outcome.exit`` is not used with ``EOF`` in the pdb wrapper anymore, but only with ``quit``.
Improved Documentation
----------------------
- :issue:`4935`: Expand docs on registering marks and the effect of ``--strict``.
Trivial/Internal Changes
------------------------
- :issue:`4942`: ``logging.raiseExceptions`` is not set to ``False`` anymore.
- :issue:`5013`: pytest now depends on :pypi:`wcwidth` to properly track unicode character sizes for more precise terminal output.
- :issue:`5059`: pytester's ``Testdir.popen()`` uses ``stdout`` and ``stderr`` via keyword arguments with defaults now (``subprocess.PIPE``).
- :issue:`5069`: The code for the short test summary in the terminal was moved to the terminal plugin.
- :issue:`5082`: Improved validation of kwargs for various methods in the pytester plugin.
- :issue:`5202`: ``record_property`` now emits a ``PytestWarning`` when used with ``junit_family=xunit2``: the fixture generates
``property`` tags as children of ``testcase``, which is not permitted according to the most
`recent schema `__.
- :issue:`5239`: Pin ``pluggy`` to ``< 1.0`` so we don't update to ``1.0`` automatically when
it gets released: there are planned breaking changes, and we want to ensure
pytest properly supports ``pluggy 1.0``.
pytest 4.4.2 (2019-05-08)
=========================
Bug Fixes
---------
- :issue:`5089`: Fix crash caused by error in ``__repr__`` function with both ``showlocals`` and verbose output enabled.
- :issue:`5139`: Eliminate core dependency on 'terminal' plugin.
- :issue:`5229`: Require ``pluggy>=0.11.0`` which reverts a dependency to ``importlib-metadata`` added in ``0.10.0``.
The ``importlib-metadata`` package cannot be imported when installed as an egg and causes issues when relying on ``setup.py`` to install test dependencies.
Improved Documentation
----------------------
- :issue:`5171`: Doc: ``pytest_ignore_collect``, ``pytest_collect_directory``, ``pytest_collect_file`` and ``pytest_pycollect_makemodule`` hooks's 'path' parameter documented type is now ``py.path.local``
- :issue:`5188`: Improve help for ``--runxfail`` flag.
Trivial/Internal Changes
------------------------
- :issue:`5182`: Removed internal and unused ``_pytest.deprecated.MARK_INFO_ATTRIBUTE``.
pytest 4.4.1 (2019-04-15)
=========================
Bug Fixes
---------
- :issue:`5031`: Environment variables are properly restored when using pytester's ``testdir`` fixture.
- :issue:`5039`: Fix regression with ``--pdbcls``, which stopped working with local modules in 4.0.0.
- :issue:`5092`: Produce a warning when unknown keywords are passed to ``pytest.param(...)``.
- :issue:`5098`: Invalidate import caches with ``monkeypatch.syspath_prepend``, which is required with namespace packages being used.
pytest 4.4.0 (2019-03-29)
=========================
Features
--------
- :issue:`2224`: ``async`` test functions are skipped and a warning is emitted when a suitable
async plugin is not installed (such as ``pytest-asyncio`` or ``pytest-trio``).
Previously ``async`` functions would not execute at all but still be marked as "passed".
- :issue:`2482`: Include new ``disable_test_id_escaping_and_forfeit_all_rights_to_community_support`` option to disable ascii-escaping in parametrized values. This may cause a series of problems and as the name makes clear, use at your own risk.
- :issue:`4718`: The ``-p`` option can now be used to early-load plugins also by entry-point name, instead of just
by module name.
This makes it possible to early load external plugins like ``pytest-cov`` in the command-line::
pytest -p pytest_cov
- :issue:`4855`: The ``--pdbcls`` option handles classes via module attributes now (e.g.
``pdb:pdb.Pdb`` with :pypi:`pdbpp`), and its validation was improved.
- :issue:`4875`: The :confval:`testpaths` configuration option is now displayed next
to the ``rootdir`` and ``inifile`` lines in the pytest header if the option is in effect, i.e., directories or file names were
not explicitly passed in the command line.
Also, ``inifile`` is only displayed if there's a configuration file, instead of an empty ``inifile:`` string.
- :issue:`4911`: Doctests can be skipped now dynamically using ``pytest.skip()``.
- :issue:`4920`: Internal refactorings have been made in order to make the implementation of the
`pytest-subtests `__ plugin
possible, which adds unittest sub-test support and a new ``subtests`` fixture as discussed in
:issue:`1367`.
For details on the internal refactorings, please see the details on the related PR.
- :issue:`4931`: pytester's ``LineMatcher`` asserts that the passed lines are a sequence.
- :issue:`4936`: Handle ``-p plug`` after ``-p no:plug``.
This can be used to override a blocked plugin (e.g. in "addopts") from the
command line etc.
- :issue:`4951`: Output capturing is handled correctly when only capturing via fixtures (capsys, capfs) with ``pdb.set_trace()``.
- :issue:`4956`: ``pytester`` sets ``$HOME`` and ``$USERPROFILE`` to the temporary directory during test runs.
This ensures to not load configuration files from the real user's home directory.
- :issue:`4980`: Namespace packages are handled better with ``monkeypatch.syspath_prepend`` and ``testdir.syspathinsert`` (via ``pkg_resources.fixup_namespace_packages``).
- :issue:`4993`: The stepwise plugin reports status information now.
- :issue:`5008`: If a ``setup.cfg`` file contains ``[tool:pytest]`` and also the no longer supported ``[pytest]`` section, pytest will use ``[tool:pytest]`` ignoring ``[pytest]``. Previously it would unconditionally error out.
This makes it simpler for plugins to support old pytest versions.
Bug Fixes
---------
- :issue:`1895`: Fix bug where fixtures requested dynamically via ``request.getfixturevalue()`` might be teardown
before the requesting fixture.
- :issue:`4851`: pytester unsets ``PYTEST_ADDOPTS`` now to not use outer options with ``testdir.runpytest()``.
- :issue:`4903`: Use the correct modified time for years after 2038 in rewritten ``.pyc`` files.
- :issue:`4928`: Fix line offsets with ``ScopeMismatch`` errors.
- :issue:`4957`: ``-p no:plugin`` is handled correctly for default (internal) plugins now, e.g. with ``-p no:capture``.
Previously they were loaded (imported) always, making e.g. the ``capfd`` fixture available.
- :issue:`4968`: The pdb ``quit`` command is handled properly when used after the ``debug`` command with :pypi:`pdbpp`.
- :issue:`4975`: Fix the interpretation of ``-qq`` option where it was being considered as ``-v`` instead.
- :issue:`4978`: ``outcomes.Exit`` is not swallowed in ``assertrepr_compare`` anymore.
- :issue:`4988`: Close logging's file handler explicitly when the session finishes.
- :issue:`5003`: Fix line offset with mark collection error (off by one).
Improved Documentation
----------------------
- :issue:`4974`: Update docs for ``pytest_cmdline_parse`` hook to note availability liminations
Trivial/Internal Changes
------------------------
- :issue:`4718`: ``pluggy>=0.9`` is now required.
- :issue:`4815`: ``funcsigs>=1.0`` is now required for Python 2.7.
- :issue:`4829`: Some left-over internal code related to ``yield`` tests has been removed.
- :issue:`4890`: Remove internally unused ``anypython`` fixture from the pytester plugin.
- :issue:`4912`: Remove deprecated Sphinx directive, ``add_description_unit()``,
pin sphinx-removed-in to >= 0.2.0 to support Sphinx 2.0.
- :issue:`4913`: Fix pytest tests invocation with custom ``PYTHONPATH``.
- :issue:`4965`: New ``pytest_report_to_serializable`` and ``pytest_report_from_serializable`` **experimental** hooks.
These hooks will be used by ``pytest-xdist``, ``pytest-subtests``, and the replacement for
resultlog to serialize and customize reports.
They are experimental, meaning that their details might change or even be removed
completely in future patch releases without warning.
Feedback is welcome from plugin authors and users alike.
- :issue:`4987`: ``Collector.repr_failure`` respects the ``--tb`` option, but only defaults to ``short`` now (with ``auto``).
pytest 4.3.1 (2019-03-11)
=========================
Bug Fixes
---------
- :issue:`4810`: Logging messages inside ``pytest_runtest_logreport()`` are now properly captured and displayed.
- :issue:`4861`: Improve validation of contents written to captured output so it behaves the same as when capture is disabled.
- :issue:`4898`: Fix ``AttributeError: FixtureRequest has no 'confg' attribute`` bug in ``testdir.copy_example``.
Trivial/Internal Changes
------------------------
- :issue:`4768`: Avoid pkg_resources import at the top-level.
pytest 4.3.0 (2019-02-16)
=========================
Deprecations
------------
- :issue:`4724`: ``pytest.warns()`` now emits a warning when it receives unknown keyword arguments.
This will be changed into an error in the future.
Features
--------
- :issue:`2753`: Usage errors from argparse are mapped to pytest's ``UsageError``.
- :issue:`3711`: Add the ``--ignore-glob`` parameter to exclude test-modules with Unix shell-style wildcards.
Add the :globalvar:`collect_ignore_glob` for ``conftest.py`` to exclude test-modules with Unix shell-style wildcards.
- :issue:`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.
- :issue:`4707`: With the help of new ``set_log_path()`` method there is a way to set ``log_file`` paths from hooks.
Bug Fixes
---------
- :issue:`4651`: ``--help`` and ``--version`` are handled with ``UsageError``.
- :issue:`4782`: Fix ``AssertionError`` with collection of broken symlinks with packages.
pytest 4.2.1 (2019-02-12)
=========================
Bug Fixes
---------
- :issue:`2895`: The ``pytest_report_collectionfinish`` hook now is also called with ``--collect-only``.
- :issue:`3899`: Do not raise ``UsageError`` when an imported package has a ``pytest_plugins.py`` child module.
- :issue:`4347`: Fix output capturing when using pdb++ with recursive debugging.
- :issue:`4592`: Fix handling of ``collect_ignore`` via parent ``conftest.py``.
- :issue:`4700`: Fix regression where ``setUpClass`` would always be called in subclasses even if all tests
were skipped by a ``unittest.skip()`` decorator applied in the subclass.
- :issue:`4739`: Fix ``parametrize(... ids=)`` when the function returns non-strings.
- :issue:`4745`: Fix/improve collection of args when passing in ``__init__.py`` and a test file.
- :issue:`4770`: ``more_itertools`` is now constrained to <6.0.0 when required for Python 2.7 compatibility.
- :issue:`526`: Fix "ValueError: Plugin already registered" exceptions when running in build directories that symlink to actual source.
Improved Documentation
----------------------
- :issue:`3899`: Add note to ``plugins.rst`` that ``pytest_plugins`` should not be used as a name for a user module containing plugins.
- :issue:`4324`: Document how to use ``raises`` and ``does_not_raise`` to write parametrized tests with conditional raises.
- :issue:`4709`: Document how to customize test failure messages when using
``pytest.warns``.
Trivial/Internal Changes
------------------------
- :issue:`4741`: Some verbosity related attributes of the TerminalReporter plugin are now
read only properties.
pytest 4.2.0 (2019-01-30)
=========================
Features
--------
- :issue:`3094`: :doc:`Classic xunit-style ` functions and methods
now obey the scope of *autouse* fixtures.
This fixes a number of surprising issues like ``setup_method`` being called before session-scoped
autouse fixtures (see :issue:`517` for an example).
- :issue:`4627`: Display a message at the end of the test session when running under Python 2.7 and 3.4 that pytest 5.0 will no longer
support those Python versions.
- :issue:`4660`: The number of *selected* tests now are also displayed when the ``-k`` or ``-m`` flags are used.
- :issue:`4688`: ``pytest_report_teststatus`` hook now can also receive a ``config`` parameter.
- :issue:`4691`: ``pytest_terminal_summary`` hook now can also receive a ``config`` parameter.
Bug Fixes
---------
- :issue:`3547`: ``--junitxml`` can emit XML compatible with Jenkins xUnit.
``junit_family`` INI option accepts ``legacy|xunit1``, which produces old style output, and ``xunit2`` that conforms more strictly to https://github.com/jenkinsci/xunit-plugin/blob/xunit-2.3.2/src/main/resources/org/jenkinsci/plugins/xunit/types/model/xsd/junit-10.xsd
- :issue:`4280`: Improve quitting from pdb, especially with ``--trace``.
Using ``q[quit]`` after ``pdb.set_trace()`` will quit pytest also.
- :issue:`4402`: Warning summary now groups warnings by message instead of by test id.
This makes the output more compact and better conveys the general idea of how much code is
actually generating warnings, instead of how many tests call that code.
- :issue:`4536`: ``monkeypatch.delattr`` handles class descriptors like ``staticmethod``/``classmethod``.
- :issue:`4649`: Restore marks being considered keywords for keyword expressions.
- :issue:`4653`: ``tmp_path`` fixture and other related ones provides resolved path (a.k.a real path)
- :issue:`4667`: ``pytest_terminal_summary`` uses result from ``pytest_report_teststatus`` hook, rather than hardcoded strings.
- :issue:`4669`: Correctly handle ``unittest.SkipTest`` exception containing non-ascii characters on Python 2.
- :issue:`4680`: Ensure the ``tmpdir`` and the ``tmp_path`` fixtures are the same folder.
- :issue:`4681`: Ensure ``tmp_path`` is always a real path.
Trivial/Internal Changes
------------------------
- :issue:`4643`: Use ``a.item()`` instead of the deprecated ``np.asscalar(a)`` in ``pytest.approx``.
``np.asscalar`` has been :doc:`deprecated ` in ``numpy 1.16.``.
- :issue:`4657`: Copy saferepr from pylib
- :issue:`4668`: The verbose word for expected failures in the teststatus report changes from ``xfail`` to ``XFAIL`` to be consistent with other test outcomes.
pytest 4.1.1 (2019-01-12)
=========================
Bug Fixes
---------
- :issue:`2256`: Show full repr with ``assert a==b`` and ``-vv``.
- :issue:`3456`: Extend Doctest-modules to ignore mock objects.
- :issue:`4617`: Fixed ``pytest.warns`` bug when context manager is reused (e.g. multiple parametrization).
- :issue:`4631`: Don't rewrite assertion when ``__getattr__`` is broken
Improved Documentation
----------------------
- :issue:`3375`: Document that using ``setup.cfg`` may crash other tools or cause hard to track down problems because it uses a different parser than ``pytest.ini`` or ``tox.ini`` files.
Trivial/Internal Changes
------------------------
- :issue:`4602`: Uninstall ``hypothesis`` in regen tox env.
pytest 4.1.0 (2019-01-05)
=========================
Removals
--------
- :issue:`2169`: ``pytest.mark.parametrize``: in previous versions, errors raised by id functions were suppressed and changed into warnings. Now the exceptions are propagated, along with a pytest message informing the node, parameter value and index where the exception occurred.
- :issue:`3078`: Remove legacy internal warnings system: ``config.warn``, ``Node.warn``. The ``pytest_logwarning`` now issues a warning when implemented.
See our :ref:`docs ` on information on how to update your code.
- :issue:`3079`: Removed support for yield tests - they are fundamentally broken because they don't support fixtures properly since collection and test execution were separated.
See our :ref:`docs ` on information on how to update your code.
- :issue:`3082`: Removed support for applying marks directly to values in ``@pytest.mark.parametrize``. Use ``pytest.param`` instead.
See our :ref:`docs ` on information on how to update your code.
- :issue:`3083`: Removed ``Metafunc.addcall``. This was the predecessor mechanism to ``@pytest.mark.parametrize``.
See our :ref:`docs ` on information on how to update your code.
- :issue:`3085`: Removed support for passing strings to ``pytest.main``. Now, always pass a list of strings instead.
See our :ref:`docs ` on information on how to update your code.
- :issue:`3086`: ``[pytest]`` section in **setup.cfg** files is no longer supported, use ``[tool:pytest]`` instead. ``setup.cfg`` files
are meant for use with ``distutils``, and a section named ``pytest`` has notoriously been a source of conflicts and bugs.
Note that for **pytest.ini** and **tox.ini** files the section remains ``[pytest]``.
- :issue:`3616`: Removed the deprecated compat properties for ``node.Class/Function/Module`` - use ``pytest.Class/Function/Module`` now.
See our :ref:`docs