Pytest

Latest version: v8.2.0

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

Scan your dependencies

Page 14 of 33

4.3.0

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

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.

4.2.1

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

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=<function>)`` 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.

4.2.0

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

Features
--------

- :issue:`3094`: :doc:`Classic xunit-style <how-to/xunit_setup>` 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 <numpy:release/1.16.0-notes>` 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.

4.1.1

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

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.

4.1.0

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

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 <config.warn and node.warn deprecated>` 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 <yield tests deprecated>` 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 <marks in pytest.parametrize deprecated>` 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 <metafunc.addcall deprecated>` 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 <passing command-line string to pytest.main deprecated>` 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 <internal classes accessed through node deprecated>` on information on how to update your code.


- :issue:`4421`: Removed the implementation of the ``pytest_namespace`` hook.

See our :ref:`docs <pytest.namespace deprecated>` on information on how to update your code.


- :issue:`4489`: Removed ``request.cached_setup``. This was the predecessor mechanism to modern fixtures.

See our :ref:`docs <cached_setup deprecated>` on information on how to update your code.


- :issue:`4535`: Removed the deprecated ``PyCollector.makeitem`` method. This method was made public by mistake a long time ago.


- :issue:`4543`: Removed support to define fixtures using the ``pytest_funcarg__`` prefix. Use the ``pytest.fixture`` decorator instead.

See our :ref:`docs <pytest_funcarg__ prefix deprecated>` on information on how to update your code.


- :issue:`4545`: Calling fixtures directly is now always an error instead of a warning.

See our :ref:`docs <calling fixtures directly deprecated>` on information on how to update your code.


- :issue:`4546`: Remove ``Node.get_marker(name)`` the return value was not usable for more than an existence check.

Use ``Node.get_closest_marker(name)`` as a replacement.


- :issue:`4547`: The deprecated ``record_xml_property`` fixture has been removed, use the more generic ``record_property`` instead.

See our :ref:`docs <record_xml_property deprecated>` for more information.


- :issue:`4548`: An error is now raised if the ``pytest_plugins`` variable is defined in a non-top-level ``conftest.py`` file (i.e., not residing in the ``rootdir``).

See our :ref:`docs <pytest_plugins in non-top-level conftest files deprecated>` for more information.


- :issue:`891`: Remove ``testfunction.markername`` attributes - use ``Node.iter_markers(name=None)`` to iterate them.



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

- :issue:`3050`: Deprecated the ``pytest.config`` global.

See :ref:`pytest.config global deprecated` for rationale.


- :issue:`3974`: Passing the ``message`` parameter of ``pytest.raises`` now issues a ``DeprecationWarning``.

It is a common mistake to think this parameter will match the exception message, while in fact
it only serves to provide a custom message in case the ``pytest.raises`` check fails. To avoid this
mistake and because it is believed to be little used, pytest is deprecating it without providing
an alternative for the moment.

If you have concerns about this, please comment on :issue:`3974`.


- :issue:`4435`: Deprecated ``raises(..., 'code(as_a_string)')`` and ``warns(..., 'code(as_a_string)')``.

See :std:ref:`raises-warns-exec` for rationale and examples.



Features
--------

- :issue:`3191`: A warning is now issued when assertions are made for ``None``.

This is a common source of confusion among new users, which write:

.. code-block:: python

assert mocked_object.assert_called_with(3, 4, 5, key="value")

When they should write:

.. code-block:: python

mocked_object.assert_called_with(3, 4, 5, key="value")

Because the ``assert_called_with`` method of mock objects already executes an assertion.

This warning will not be issued when ``None`` is explicitly checked. An assertion like:

.. code-block:: python

assert variable is None

will not issue the warning.


- :issue:`3632`: Richer equality comparison introspection on ``AssertionError`` for objects created using `attrs <https://www.attrs.org/en/stable/>`__ or :mod:`dataclasses` (Python 3.7+, :pypi:`backported to 3.6 <dataclasses>`).


- :issue:`4278`: ``CACHEDIR.TAG`` files are now created inside cache directories.

Those files are part of the `Cache Directory Tagging Standard <https://bford.info/cachedir/spec.html>`__, and can
be used by backup or synchronization programs to identify pytest's cache directory as such.


- :issue:`4292`: ``pytest.outcomes.Exit`` is derived from ``SystemExit`` instead of ``KeyboardInterrupt``. This allows us to better handle ``pdb`` exiting.


- :issue:`4371`: Updated the ``--collect-only`` option to display test descriptions when ran using ``--verbose``.


- :issue:`4386`: Restructured ``ExceptionInfo`` object construction and ensure incomplete instances have a ``repr``/``str``.


- :issue:`4416`: pdb: added support for keyword arguments with ``pdb.set_trace``.

It handles ``header`` similar to Python 3.7 does it, and forwards any
other keyword arguments to the ``Pdb`` constructor.

This allows for ``__import__("pdb").set_trace(skip=["foo.*"])``.


- :issue:`4483`: Added ini parameter ``junit_duration_report`` to optionally report test call durations, excluding setup and teardown times.

The JUnit XML specification and the default pytest behavior is to include setup and teardown times in the test duration
report. You can include just the call durations instead (excluding setup and teardown) by adding this to your ``pytest.ini`` file:

.. code-block:: ini

[pytest]
junit_duration_report = call


- :issue:`4532`: ``-ra`` now will show errors and failures last, instead of as the first items in the summary.

This makes it easier to obtain a list of errors and failures to run tests selectively.


- :issue:`4599`: ``pytest.importorskip`` now supports a ``reason`` parameter, which will be shown when the
requested module cannot be imported.



Bug Fixes
---------

- :issue:`3532`: ``-p`` now accepts its argument without a space between the value, for example ``-pmyplugin``.


- :issue:`4327`: ``approx`` again works with more generic containers, more precisely instances of ``Iterable`` and ``Sized`` instead of more restrictive ``Sequence``.


- :issue:`4397`: Ensure that node ids are printable.


- :issue:`4435`: Fixed ``raises(..., 'code(string)')`` frame filename.


- :issue:`4458`: Display actual test ids in ``--collect-only``.



Improved Documentation
----------------------

- :issue:`4557`: Markers example documentation page updated to support latest pytest version.


- :issue:`4558`: Update cache documentation example to correctly show cache hit and miss.


- :issue:`4580`: Improved detailed summary report documentation.



Trivial/Internal Changes
------------------------

- :issue:`4447`: Changed the deprecation type of ``--result-log`` to ``PytestDeprecationWarning``.

It was decided to remove this feature at the next major revision.

4.0.2

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

Bug Fixes
---------

- :issue:`4265`: Validate arguments from the ``PYTEST_ADDOPTS`` environment variable and the ``addopts`` ini option separately.


- :issue:`4435`: Fix ``raises(..., 'code(string)')`` frame filename.


- :issue:`4500`: When a fixture yields and a log call is made after the test runs, and, if the test is interrupted, capture attributes are ``None``.


- :issue:`4538`: Raise ``TypeError`` for ``with raises(..., match=<non-None falsey value>)``.



Improved Documentation
----------------------

- :issue:`1495`: Document common doctest fixture directory tree structure pitfalls

Page 14 of 33

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.