Pytest

Latest version: v8.2.0

Safety actively analyzes 630254 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 11 of 33

5.0.0

=========================

Important
---------

This release is a Python3.5+ only release.

For more details, see our `Python 2.7 and 3.4 support plan
<https://docs.pytest.org/en/7.0.x/py27-py34-deprecation.html>`_.

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 <https://github.com/pytest-dev/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.

4.6.11

==========================

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.

4.6.10

==========================

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 <https://docs.pytest.org/en/7.0.x/py27-py34-deprecation.html#what-goes-into-4-6-x-releases>`_
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.

4.6.9

=========================

Bug Fixes
---------

- :issue:`6301`: Fix assertion rewriting for egg-based distributions and ``editable`` installs (``pip install --editable``).

4.6.8

=========================

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.

4.6.7

=========================

Bug Fixes
---------

- :issue:`5477`: The XML file produced by ``--junitxml`` now correctly contain a ``<testsuites>`` 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).

Page 11 of 33

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.