diff --git a/.github/workflows/update-plugin-list.yml b/.github/workflows/update-plugin-list.yml index d5a6efb54..17c6364f4 100644 --- a/.github/workflows/update-plugin-list.yml +++ b/.github/workflows/update-plugin-list.yml @@ -31,7 +31,7 @@ jobs: - name: Install dependencies run: | python -m pip install --upgrade pip - pip install packaging requests tabulate[widechars] + pip install packaging requests tabulate[widechars] tqdm - name: Update Plugin List run: python scripts/update-plugin-list.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d80376b0a..40eb24c07 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -21,7 +21,7 @@ repos: exclude: _pytest/(debugging|hookspec).py language_version: python3 - repo: https://github.com/PyCQA/flake8 - rev: 3.9.2 + rev: 4.0.1 hooks: - id: flake8 language_version: python3 @@ -39,7 +39,7 @@ repos: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/asottile/setup-cfg-fmt - rev: v1.17.0 + rev: v1.18.0 hooks: - id: setup-cfg-fmt args: [--max-py-version=3.10] @@ -48,7 +48,7 @@ repos: hooks: - id: python-use-type-annotations - repo: https://github.com/pre-commit/mirrors-mypy - rev: v0.910 + rev: v0.910-1 hooks: - id: mypy files: ^(src/|testing/) diff --git a/.readthedocs.yml b/.readthedocs.yml index 0176c2640..10c21fd8f 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -7,6 +7,10 @@ python: - method: pip path: . +build: + apt_packages: + - inkscape + formats: - epub - pdf diff --git a/AUTHORS b/AUTHORS index bfc2d3e46..153375dca 100644 --- a/AUTHORS +++ b/AUTHORS @@ -13,6 +13,7 @@ Ahn Ki-Wook Akiomi Kamakura Alan Velasco Alexander Johnson +Alexander King Alexei Kozlenok Allan Feldman Aly Sivji @@ -76,6 +77,7 @@ Christopher Gilling Claire Cecil Claudio Madotto CrazyMerlyn +Cristian Vera Cyrus Maden Damian Skrzypczak Daniel Grana diff --git a/changelog/451.doc.rst b/changelog/451.doc.rst new file mode 100644 index 000000000..3c8075489 --- /dev/null +++ b/changelog/451.doc.rst @@ -0,0 +1 @@ +The PDF documentation’s list of plugins doesn’t run off the page anymore. diff --git a/changelog/7259.breaking.rst b/changelog/7259.breaking.rst new file mode 100644 index 000000000..37f2fe6d7 --- /dev/null +++ b/changelog/7259.breaking.rst @@ -0,0 +1,8 @@ +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. diff --git a/changelog/7259.deprecation.rst b/changelog/7259.deprecation.rst new file mode 100644 index 000000000..c0307740d --- /dev/null +++ b/changelog/7259.deprecation.rst @@ -0,0 +1,3 @@ +``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. diff --git a/changelog/7469.deprecation.rst b/changelog/7469.deprecation.rst index 423b1633b..ea8c7c0b4 100644 --- a/changelog/7469.deprecation.rst +++ b/changelog/7469.deprecation.rst @@ -8,5 +8,6 @@ Directly constructing the following classes is now deprecated: - ``_pytest._code.ExceptionInfo`` - ``_pytest.config.argparsing.Parser`` - ``_pytest.config.argparsing.OptionGroup`` +- ``_pytest.pytester.HookRecorder`` -These have always been considered private, but now issue a deprecation warning, which may become a hard error in pytest 8.0.0. +These constructors have always been considered private, but now issue a deprecation warning, which may become a hard error in pytest 8. diff --git a/changelog/7469.feature.rst b/changelog/7469.feature.rst index 301317087..d1dd8359b 100644 --- a/changelog/7469.feature.rst +++ b/changelog/7469.feature.rst @@ -12,8 +12,12 @@ The newly-exported types are: - ``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 :func:`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. -Constructing them directly is not supported; they are only meant for use in type annotations. +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. diff --git a/changelog/7864.improvement.rst b/changelog/7864.improvement.rst new file mode 100644 index 000000000..f5627be5e --- /dev/null +++ b/changelog/7864.improvement.rst @@ -0,0 +1,4 @@ +Improved error messages when parsing warning filters. + +Previously pytest would show an internal traceback, which besides ugly sometimes would hide the cause +of the problem (for example an ``ImportError`` while importing a specific warning type). diff --git a/changelog/8994.improvement.rst b/changelog/8994.improvement.rst new file mode 100644 index 000000000..2c8a2ef83 --- /dev/null +++ b/changelog/8994.improvement.rst @@ -0,0 +1,2 @@ +Included the module of the class in the error message about direct +node construction (without using ``from_parent``). diff --git a/changelog/9023.feature.rst b/changelog/9023.feature.rst new file mode 100644 index 000000000..86a819a84 --- /dev/null +++ b/changelog/9023.feature.rst @@ -0,0 +1,4 @@ + +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. diff --git a/changelog/9113.feature.rst b/changelog/9113.feature.rst new file mode 100644 index 000000000..f16e6ea63 --- /dev/null +++ b/changelog/9113.feature.rst @@ -0,0 +1,2 @@ +: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. diff --git a/changelog/9131.bugfix.rst b/changelog/9131.bugfix.rst new file mode 100644 index 000000000..837bb596d --- /dev/null +++ b/changelog/9131.bugfix.rst @@ -0,0 +1 @@ +Fixed the URL used by ``--pastebin`` to use `bpa.st `__. diff --git a/changelog/9163.bugfix.rst b/changelog/9163.bugfix.rst new file mode 100644 index 000000000..fb559d10f --- /dev/null +++ b/changelog/9163.bugfix.rst @@ -0,0 +1 @@ +The end line number and end column offset are now properly set for rewritten assert statements. diff --git a/changelog/9169.bugfix.rst b/changelog/9169.bugfix.rst new file mode 100644 index 000000000..83fce0a38 --- /dev/null +++ b/changelog/9169.bugfix.rst @@ -0,0 +1 @@ +Support for the ``files`` API from ``importlib.resources`` within rewritten files. diff --git a/changelog/9205.improvement.rst b/changelog/9205.improvement.rst new file mode 100644 index 000000000..edfc30089 --- /dev/null +++ b/changelog/9205.improvement.rst @@ -0,0 +1 @@ +:meth:`pytest.Cache.set` now preserves key order when saving dicts. diff --git a/changelog/9210.doc.rst b/changelog/9210.doc.rst new file mode 100644 index 000000000..02a850c08 --- /dev/null +++ b/changelog/9210.doc.rst @@ -0,0 +1 @@ +Remove incorrect docs about ``confcutdir`` being a configuration option: it can only be set through the ``--confcutdir`` command-line option. diff --git a/doc/en/announce/release-2.4.0.rst b/doc/en/announce/release-2.4.0.rst index 68297b26c..138cc8957 100644 --- a/doc/en/announce/release-2.4.0.rst +++ b/doc/en/announce/release-2.4.0.rst @@ -23,14 +23,13 @@ a full list of details. A few feature highlights: called if the corresponding setup method succeeded. - integrate tab-completion on command line options if you - have `argcomplete `_ - configured. + have :pypi:`argcomplete` configured. - allow boolean expression directly with skipif/xfail if a "reason" is also specified. - a new hook ``pytest_load_initial_conftests`` allows plugins like - `pytest-django `_ to + :pypi:`pytest-django` to influence the environment before conftest files import ``django``. - reporting: color the last line red or green depending if diff --git a/doc/en/changelog.rst b/doc/en/changelog.rst index 4d4f0cc02..8736ac4b6 100644 --- a/doc/en/changelog.rst +++ b/doc/en/changelog.rst @@ -1004,7 +1004,7 @@ Trivial/Internal Changes - `#7264 `_: The dependency on the ``wcwidth`` package has been removed. -- `#7291 `_: Replaced ``py.iniconfig`` with `iniconfig `__. +- `#7291 `_: Replaced ``py.iniconfig`` with :pypi:`iniconfig`. - `#7295 `_: ``src/_pytest/config/__init__.py`` now uses the ``warnings`` module to report warnings instead of ``sys.stderr.write``. @@ -1795,7 +1795,7 @@ Removals For more information consult :std:doc:`deprecations` in the docs. -- `#5565 `_: Removed unused support code for `unittest2 `__. +- `#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 @@ -2520,7 +2520,7 @@ Trivial/Internal Changes - `#4942 `_: ``logging.raiseExceptions`` is not set to ``False`` anymore. -- `#5013 `_: pytest now depends on `wcwidth `__ to properly track unicode character sizes for more precise terminal output. +- `#5013 `_: pytest now depends on :pypi:`wcwidth` to properly track unicode character sizes for more precise terminal output. - `#5059 `_: pytester's ``Testdir.popen()`` uses ``stdout`` and ``stderr`` via keyword arguments with defaults now (``subprocess.PIPE``). @@ -2618,9 +2618,7 @@ Features - `#4855 `_: The ``--pdbcls`` option handles classes via module attributes now (e.g. - ``pdb:pdb.Pdb`` with `pdb++`_), and its validation was improved. - - .. _pdb++: https://pypi.org/project/pdbpp/ + ``pdb:pdb.Pdb`` with :pypi:`pdbpp`), and its validation was improved. - `#4875 `_: The :confval:`testpaths` configuration option is now displayed next @@ -2691,9 +2689,7 @@ Bug Fixes Previously they were loaded (imported) always, making e.g. the ``capfd`` fixture available. -- `#4968 `_: The pdb ``quit`` command is handled properly when used after the ``debug`` command with `pdb++`_. - - .. _pdb++: https://pypi.org/project/pdbpp/ +- `#4968 `_: The pdb ``quit`` command is handled properly when used after the ``debug`` command with :pypi:`pdbpp`. - `#4975 `_: Fix the interpretation of ``-qq`` option where it was being considered as ``-v`` instead. @@ -3124,7 +3120,7 @@ Features will not issue the warning. -- `#3632 `_: Richer equality comparison introspection on ``AssertionError`` for objects created using `attrs `__ or :mod:`dataclasses` (Python 3.7+, `backported to 3.6 `__). +- `#3632 `_: Richer equality comparison introspection on ``AssertionError`` for objects created using `attrs `__ or :mod:`dataclasses` (Python 3.7+, :pypi:`backported to 3.6 `). - `#4278 `_: ``CACHEDIR.TAG`` files are now created inside cache directories. @@ -4865,8 +4861,7 @@ Features markers. Also, a ``caplog`` fixture is available that enables users to test the captured log during specific tests (similar to ``capsys`` for example). For more information, please see the :doc:`logging docs `. This feature was - introduced by merging the popular `pytest-catchlog - `_ plugin, thanks to `Thomas Hisch + introduced by merging the popular :pypi:`pytest-catchlog` plugin, thanks to `Thomas Hisch `_. Be advised that during the merging the backward compatibility interface with the defunct ``pytest-capturelog`` has been dropped. (`#2794 `_) @@ -4943,7 +4938,7 @@ Bug Fixes Trivial/Internal Changes ------------------------ -- pytest now depends on `attrs `__ for internal +- pytest now depends on :pypi:`attrs` for internal structures to ease code maintainability. (`#2641 `_) diff --git a/doc/en/conf.py b/doc/en/conf.py index 61f9dd5d5..51ab612ed 100644 --- a/doc/en/conf.py +++ b/doc/en/conf.py @@ -17,6 +17,7 @@ # The short X.Y version. import ast import os +import shutil import sys from typing import List from typing import TYPE_CHECKING @@ -38,6 +39,10 @@ autodoc_member_order = "bysource" autodoc_typehints = "description" todo_include_todos = 1 +# Use a different latex engine due to possible Unicode characters in the documentation: +# https://docs.readthedocs.io/en/stable/guides/pdf-non-ascii-languages.html +latex_engine = "xelatex" + # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. @@ -50,6 +55,7 @@ extensions = [ "pygments_pytest", "sphinx.ext.autodoc", "sphinx.ext.autosummary", + "sphinx.ext.extlinks", "sphinx.ext.intersphinx", "sphinx.ext.todo", "sphinx.ext.viewcode", @@ -57,6 +63,13 @@ extensions = [ "sphinxcontrib_trio", ] +# Building PDF docs on readthedocs requires inkscape for svg to pdf +# conversion. The relevant plugin is not useful for normal HTML builds, but +# it still raises warnings and fails CI if inkscape is not available. So +# only use the plugin if inkscape is actually available. +if shutil.which("inkscape"): + extensions.append("sphinxcontrib.inkscapeconverter") + # Add any paths that contain templates here, relative to this directory. templates_path = ["_templates"] @@ -133,6 +146,11 @@ linkcheck_ignore = [ linkcheck_workers = 5 +extlinks = { + "pypi": ("https://pypi.org/project/%s/", ""), +} + + # -- Options for HTML output --------------------------------------------------- sys.path.append(os.path.abspath("_themes")) @@ -350,6 +368,14 @@ intersphinx_mapping = { "pluggy": ("https://pluggy.readthedocs.io/en/stable", None), "python": ("https://docs.python.org/3", None), "numpy": ("https://numpy.org/doc/stable", None), + "pip": ("https://pip.pypa.io/en/stable", None), + "tox": ("https://tox.wiki/en/stable", None), + "virtualenv": ("https://virtualenv.pypa.io/en/stable", None), + "django": ( + "http://docs.djangoproject.com/en/stable", + "http://docs.djangoproject.com/en/stable/_objects", + ), + "setuptools": ("https://setuptools.pypa.io/en/stable", None), } diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 775bc1958..b82dd8521 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -18,17 +18,40 @@ Deprecated Features Below is a complete list of all pytest features which are considered deprecated. Using those features will issue :class:`PytestWarning` or subclasses, which can be filtered using :ref:`standard warning filters `. +.. _node-ctor-fspath-deprecation: + +``fspath`` argument for Node constructors replaced with ``pathlib.Path`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. deprecated:: 7.0 + +In order to support the transition from ``py.path.local`` to :mod:`pathlib`, +the ``fspath`` argument to :class:`~_pytest.nodes.Node` constructors like +:func:`pytest.Function.from_parent()` and :func:`pytest.Class.from_parent()` +is now deprecated. + +Plugins which construct nodes should pass the ``path`` argument, of type +:class:`pathlib.Path`, instead of the ``fspath`` argument. + +Plugins which implement custom items and collectors are encouraged to replace +``py.path.local`` ``fspath`` parameters with ``pathlib.Path`` parameters, and +drop any other usage of the ``py`` library if possible. + + +.. _legacy-path-hooks-deprecated: ``py.path.local`` arguments for hooks replaced with ``pathlib.Path`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -In order to support the transition to :mod:`pathlib`, the following hooks now receive additional arguments: +.. deprecated:: 7.0 -* :func:`pytest_ignore_collect(fspath: pathlib.Path) <_pytest.hookspec.pytest_ignore_collect>` -* :func:`pytest_collect_file(fspath: pathlib.Path) <_pytest.hookspec.pytest_collect_file>` -* :func:`pytest_pycollect_makemodule(fspath: pathlib.Path) <_pytest.hookspec.pytest_pycollect_makemodule>` -* :func:`pytest_report_header(startpath: pathlib.Path) <_pytest.hookspec.pytest_report_header>` -* :func:`pytest_report_collectionfinish(startpath: pathlib.Path) <_pytest.hookspec.pytest_report_collectionfinish>` +In order to support the transition from ``py.path.local`` to :mod:`pathlib`, the following hooks now receive additional arguments: + +* :func:`pytest_ignore_collect(fspath: pathlib.Path) <_pytest.hookspec.pytest_ignore_collect>` instead of ``path`` +* :func:`pytest_collect_file(fspath: pathlib.Path) <_pytest.hookspec.pytest_collect_file>` instead of ``path`` +* :func:`pytest_pycollect_makemodule(fspath: pathlib.Path) <_pytest.hookspec.pytest_pycollect_makemodule>` instead of ``path`` +* :func:`pytest_report_header(startpath: pathlib.Path) <_pytest.hookspec.pytest_report_header>` instead of ``startdir`` +* :func:`pytest_report_collectionfinish(startpath: pathlib.Path) <_pytest.hookspec.pytest_report_collectionfinish>` instead of ``startdir`` The accompanying ``py.path.local`` based paths have been deprecated: plugins which manually invoke those hooks should only pass the new ``pathlib.Path`` arguments, and users should change their hook implementations to use the new ``pathlib.Path`` arguments. @@ -59,7 +82,7 @@ Implement the :func:`pytest_load_initial_conftests <_pytest.hookspec.pytest_load Diamond inheritance between :class:`pytest.File` and :class:`pytest.Item` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. deprecated:: 6.3 +.. deprecated:: 7.0 Inheriting from both Item and file at once has never been supported officially, however some plugins providing linting/code analysis have been using this as a hack. @@ -86,7 +109,7 @@ scheduled for removal in pytest 7 (deprecated since pytest 2.4.0): Raising ``unittest.SkipTest`` during collection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -.. deprecated:: 6.3 +.. deprecated:: 7.0 Raising :class:`unittest.SkipTest` to skip collection of tests during the pytest collection phase is deprecated. Use :func:`pytest.skip` instead. diff --git a/doc/en/example/fixtures/fixture_availability.svg b/doc/en/example/fixtures/fixture_availability.svg index 3ca28447c..066caac34 100644 --- a/doc/en/example/fixtures/fixture_availability.svg +++ b/doc/en/example/fixtures/fixture_availability.svg @@ -1,4 +1,4 @@ - +