diff --git a/changelog/10865.improvement.rst b/changelog/10865.improvement.rst deleted file mode 100644 index a5ced8e9a..000000000 --- a/changelog/10865.improvement.rst +++ /dev/null @@ -1,3 +0,0 @@ -:func:`pytest.warns` now validates that :func:`warnings.warn` was called with a `str` or a `Warning`. -Currently in Python it is possible to use other types, however this causes an exception when :func:`warnings.filterwarnings` is used to filter those warnings (see `CPython #103577 `__ for a discussion). -While this can be considered a bug in CPython, we decided to put guards in pytest as the error message produced without this check in place is confusing. diff --git a/changelog/11311.improvement.rst b/changelog/11311.improvement.rst deleted file mode 100644 index 0072f3974..000000000 --- a/changelog/11311.improvement.rst +++ /dev/null @@ -1,4 +0,0 @@ -When using ``--override-ini`` for paths in invocations without a configuration file defined, the current working directory is used -as the relative directory. - -Previoulsy this would raise an :class:`AssertionError`. diff --git a/changelog/11475.feature.rst b/changelog/11475.feature.rst deleted file mode 100644 index 42550235d..000000000 --- a/changelog/11475.feature.rst +++ /dev/null @@ -1,3 +0,0 @@ -Added the new :confval:`consider_namespace_packages` configuration option, defaulting to ``False``. - -If set to ``True``, pytest will attempt to identify modules that are part of `namespace packages `__ when importing modules. diff --git a/changelog/11475.improvement.rst b/changelog/11475.improvement.rst deleted file mode 100644 index 4f6a4bffa..000000000 --- a/changelog/11475.improvement.rst +++ /dev/null @@ -1,3 +0,0 @@ -:ref:`--import-mode=importlib ` now tries to import modules using the standard import mechanism (but still without changing :py:data:`sys.path`), falling back to importing modules directly only if that fails. - -This means that installed packages will be imported under their canonical name if possible first, for example ``app.core.models``, instead of having the module name always be derived from their path (for example ``.env310.lib.site_packages.app.core.models``). diff --git a/changelog/11653.feature.rst b/changelog/11653.feature.rst deleted file mode 100644 index f165c3f8e..000000000 --- a/changelog/11653.feature.rst +++ /dev/null @@ -1,2 +0,0 @@ -Added the new :confval:`verbosity_test_cases` configuration option for fine-grained control of test execution verbosity. -See :ref:`Fine-grained verbosity ` for more details. diff --git a/changelog/11785.trivial.rst b/changelog/11785.trivial.rst deleted file mode 100644 index b6b74d0da..000000000 --- a/changelog/11785.trivial.rst +++ /dev/null @@ -1,7 +0,0 @@ -Some changes were made to private functions which may affect plugins which access them: - -- ``FixtureManager._getautousenames()`` now takes a ``Node`` itself instead of the nodeid. -- ``FixtureManager.getfixturedefs()`` now takes the ``Node`` itself instead of the nodeid. -- The ``_pytest.nodes.iterparentnodeids()`` function is removed without replacement. - Prefer to traverse the node hierarchy itself instead. - If you really need to, copy the function from the previous pytest release. diff --git a/changelog/11790.doc.rst b/changelog/11790.doc.rst deleted file mode 100644 index 648b20b96..000000000 --- a/changelog/11790.doc.rst +++ /dev/null @@ -1 +0,0 @@ -Documented the retention of temporary directories created using the ``tmp_path`` fixture in more detail. diff --git a/changelog/11801.improvement.rst b/changelog/11801.improvement.rst deleted file mode 100644 index d9e5f8483..000000000 --- a/changelog/11801.improvement.rst +++ /dev/null @@ -1,2 +0,0 @@ -Added the :func:`iter_parents() <_pytest.nodes.Node.iter_parents>` helper method on nodes. -It is similar to :func:`listchain <_pytest.nodes.Node.listchain>`, but goes from bottom to top, and returns an iterator, not a list. diff --git a/changelog/11850.improvement.rst b/changelog/11850.improvement.rst deleted file mode 100644 index 87fc0953c..000000000 --- a/changelog/11850.improvement.rst +++ /dev/null @@ -1 +0,0 @@ -Added support for :data:`sys.last_exc` for post-mortem debugging on Python>=3.12. diff --git a/changelog/11904.bugfix.rst b/changelog/11904.bugfix.rst deleted file mode 100644 index 2aed9bcb0..000000000 --- a/changelog/11904.bugfix.rst +++ /dev/null @@ -1,3 +0,0 @@ -Fixed a regression in pytest 8.0.0 that would cause test collection to fail due to permission errors when using ``--pyargs``. - -This change improves the collection tree for tests specified using ``--pyargs``, see :pull:`12043` for a comparison with pytest 8.0 and <8. diff --git a/changelog/11962.improvement.rst b/changelog/11962.improvement.rst deleted file mode 100644 index 453b99d33..000000000 --- a/changelog/11962.improvement.rst +++ /dev/null @@ -1 +0,0 @@ -In case no other suitable candidates for configuration file are found, a ``pyproject.toml`` (even without a ``[tool.pytest.ini_options]`` table) will be considered as the configuration file and define the ``rootdir``. diff --git a/changelog/11978.improvement.rst b/changelog/11978.improvement.rst deleted file mode 100644 index 1f1143dac..000000000 --- a/changelog/11978.improvement.rst +++ /dev/null @@ -1,3 +0,0 @@ -Add ``--log-file-mode`` option to the logging plugin, enabling appending to log-files. This option accepts either ``"w"`` or ``"a"`` and defaults to ``"w"``. - -Previously, the mode was hard-coded to be ``"w"`` which truncates the file before logging. diff --git a/changelog/12011.bugfix.rst b/changelog/12011.bugfix.rst deleted file mode 100644 index 5b755ade3..000000000 --- a/changelog/12011.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fixed a regression in 8.0.1 whereby ``setup_module`` xunit-style fixtures are not executed when ``--doctest-modules`` is passed. diff --git a/changelog/12014.bugfix.rst b/changelog/12014.bugfix.rst deleted file mode 100644 index 344bf8b7e..000000000 --- a/changelog/12014.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fix the ``stacklevel`` used when warning about marks used on fixtures. diff --git a/changelog/12039.bugfix.rst b/changelog/12039.bugfix.rst deleted file mode 100644 index 267eae6b8..000000000 --- a/changelog/12039.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fixed a regression in ``8.0.2`` where tests created using :fixture:`tmp_path` have been collected multiple times in CI under Windows. diff --git a/changelog/12047.improvement.rst b/changelog/12047.improvement.rst deleted file mode 100644 index e9ad5eddc..000000000 --- a/changelog/12047.improvement.rst +++ /dev/null @@ -1,2 +0,0 @@ -When multiple finalizers of a fixture raise an exception, now all exceptions are reported as an exception group. -Previously, only the first exception was reported. diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst index 5374e8c75..68cae83d7 100644 --- a/doc/en/announce/index.rst +++ b/doc/en/announce/index.rst @@ -6,6 +6,7 @@ Release announcements :maxdepth: 2 + release-8.1.0 release-8.0.2 release-8.0.1 release-8.0.0 diff --git a/doc/en/announce/release-8.1.0.rst b/doc/en/announce/release-8.1.0.rst new file mode 100644 index 000000000..62cafdd78 --- /dev/null +++ b/doc/en/announce/release-8.1.0.rst @@ -0,0 +1,54 @@ +pytest-8.1.0 +======================================= + +The pytest team is proud to announce the 8.1.0 release! + +This release contains new features, improvements, and bug fixes, +the full list of changes is available in the changelog: + + https://docs.pytest.org/en/stable/changelog.html + +For complete documentation, please visit: + + https://docs.pytest.org/en/stable/ + +As usual, you can upgrade from PyPI via: + + pip install -U pytest + +Thanks to all of the contributors to this release: + +* Ben Brown +* Ben Leith +* Bruno Oliveira +* Clément Robert +* Dave Hall +* Dương Quốc Khánh +* Eero Vaher +* Eric Larson +* Fabian Sturm +* Faisal Fawad +* Florian Bruhin +* Franck Charras +* Joachim B Haga +* John Litborn +* Loïc Estève +* Marc Bresson +* Patrick Lannigan +* Pierre Sassoulas +* Ran Benita +* Reagan Lee +* Ronny Pfannschmidt +* Russell Martin +* clee2000 +* donghui +* faph +* jakkdl +* mrbean-bremen +* robotherapist +* whysage +* woutdenolf + + +Happy testing, +The pytest Development Team diff --git a/doc/en/builtin.rst b/doc/en/builtin.rst index e9e42b9e8..1e1210648 100644 --- a/doc/en/builtin.rst +++ b/doc/en/builtin.rst @@ -33,7 +33,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a Values can be any object handled by the json stdlib module. - capsysbinary -- .../_pytest/capture.py:1007 + capsysbinary -- .../_pytest/capture.py:1008 Enable bytes capturing of writes to ``sys.stdout`` and ``sys.stderr``. The captured output is made available via ``capsysbinary.readouterr()`` @@ -50,7 +50,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a captured = capsysbinary.readouterr() assert captured.out == b"hello\n" - capfd -- .../_pytest/capture.py:1034 + capfd -- .../_pytest/capture.py:1035 Enable text capturing of writes to file descriptors ``1`` and ``2``. The captured output is made available via ``capfd.readouterr()`` method @@ -67,7 +67,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a captured = capfd.readouterr() assert captured.out == "hello\n" - capfdbinary -- .../_pytest/capture.py:1061 + capfdbinary -- .../_pytest/capture.py:1062 Enable bytes capturing of writes to file descriptors ``1`` and ``2``. The captured output is made available via ``capfd.readouterr()`` method @@ -84,7 +84,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a captured = capfdbinary.readouterr() assert captured.out == b"hello\n" - capsys -- .../_pytest/capture.py:980 + capsys -- .../_pytest/capture.py:981 Enable text capturing of writes to ``sys.stdout`` and ``sys.stderr``. The captured output is made available via ``capsys.readouterr()`` method @@ -101,7 +101,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a captured = capsys.readouterr() assert captured.out == "hello\n" - doctest_namespace [session scope] -- .../_pytest/doctest.py:745 + doctest_namespace [session scope] -- .../_pytest/doctest.py:737 Fixture that returns a :py:class:`dict` that will be injected into the namespace of doctests. @@ -115,7 +115,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a For more details: :ref:`doctest_namespace`. - pytestconfig [session scope] -- .../_pytest/fixtures.py:1354 + pytestconfig [session scope] -- .../_pytest/fixtures.py:1346 Session-scoped fixture that returns the session's :class:`pytest.Config` object. @@ -170,18 +170,18 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a `pytest-xdist `__ plugin. See :issue:`7767` for details. - tmpdir_factory [session scope] -- .../_pytest/legacypath.py:302 + tmpdir_factory [session scope] -- .../_pytest/legacypath.py:317 Return a :class:`pytest.TempdirFactory` instance for the test session. - tmpdir -- .../_pytest/legacypath.py:309 + tmpdir -- .../_pytest/legacypath.py:324 Return a temporary directory path object which is unique to each test function invocation, created as a sub directory of the base temporary directory. By default, a new base temporary directory is created each test session, and old bases are removed after 3 sessions, to aid in debugging. If - ``--basetemp`` is used then it is cleared each session. See :ref:`base - temporary directory`. + ``--basetemp`` is used then it is cleared each session. See + :ref:`temporary directory location and retention`. The returned object is a `legacy_path`_ object. @@ -192,7 +192,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a .. _legacy_path: https://py.readthedocs.io/en/latest/path.html - caplog -- .../_pytest/logging.py:594 + caplog -- .../_pytest/logging.py:601 Access and control log capturing. Captured logs are available through the following properties/methods:: @@ -227,7 +227,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a To undo modifications done by the fixture in a contained scope, use :meth:`context() `. - recwarn -- .../_pytest/recwarn.py:32 + recwarn -- .../_pytest/recwarn.py:31 Return a :class:`WarningsRecorder` instance that records all warnings emitted by test functions. See https://docs.pytest.org/en/latest/how-to/capture-warnings.html for information @@ -245,8 +245,8 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a and old bases are removed after 3 sessions, to aid in debugging. This behavior can be configured with :confval:`tmp_path_retention_count` and :confval:`tmp_path_retention_policy`. - If ``--basetemp`` is used then it is cleared each session. See :ref:`base - temporary directory`. + If ``--basetemp`` is used then it is cleared each session. See + :ref:`temporary directory location and retention`. The returned object is a :class:`pathlib.Path` object. diff --git a/doc/en/changelog.rst b/doc/en/changelog.rst index bdf5a1550..1c2ef95f5 100644 --- a/doc/en/changelog.rst +++ b/doc/en/changelog.rst @@ -28,6 +28,98 @@ with advance notice in the **Deprecations** section of releases. .. towncrier release notes start +pytest 8.1.0 (2024-03-03) +========================= + +Features +-------- + +- `#11475 `_: Added the new :confval:`consider_namespace_packages` configuration option, defaulting to ``False``. + + If set to ``True``, pytest will attempt to identify modules that are part of `namespace packages `__ when importing modules. + + +- `#11653 `_: Added the new :confval:`verbosity_test_cases` configuration option for fine-grained control of test execution verbosity. + See :ref:`Fine-grained verbosity ` for more details. + + + +Improvements +------------ + +- `#10865 `_: :func:`pytest.warns` now validates that :func:`warnings.warn` was called with a `str` or a `Warning`. + Currently in Python it is possible to use other types, however this causes an exception when :func:`warnings.filterwarnings` is used to filter those warnings (see `CPython #103577 `__ for a discussion). + While this can be considered a bug in CPython, we decided to put guards in pytest as the error message produced without this check in place is confusing. + + +- `#11311 `_: When using ``--override-ini`` for paths in invocations without a configuration file defined, the current working directory is used + as the relative directory. + + Previoulsy this would raise an :class:`AssertionError`. + + +- `#11475 `_: :ref:`--import-mode=importlib ` now tries to import modules using the standard import mechanism (but still without changing :py:data:`sys.path`), falling back to importing modules directly only if that fails. + + This means that installed packages will be imported under their canonical name if possible first, for example ``app.core.models``, instead of having the module name always be derived from their path (for example ``.env310.lib.site_packages.app.core.models``). + + +- `#11801 `_: Added the :func:`iter_parents() <_pytest.nodes.Node.iter_parents>` helper method on nodes. + It is similar to :func:`listchain <_pytest.nodes.Node.listchain>`, but goes from bottom to top, and returns an iterator, not a list. + + +- `#11850 `_: Added support for :data:`sys.last_exc` for post-mortem debugging on Python>=3.12. + + +- `#11962 `_: In case no other suitable candidates for configuration file are found, a ``pyproject.toml`` (even without a ``[tool.pytest.ini_options]`` table) will be considered as the configuration file and define the ``rootdir``. + + +- `#11978 `_: Add ``--log-file-mode`` option to the logging plugin, enabling appending to log-files. This option accepts either ``"w"`` or ``"a"`` and defaults to ``"w"``. + + Previously, the mode was hard-coded to be ``"w"`` which truncates the file before logging. + + +- `#12047 `_: When multiple finalizers of a fixture raise an exception, now all exceptions are reported as an exception group. + Previously, only the first exception was reported. + + + +Bug Fixes +--------- + +- `#11904 `_: Fixed a regression in pytest 8.0.0 that would cause test collection to fail due to permission errors when using ``--pyargs``. + + This change improves the collection tree for tests specified using ``--pyargs``, see :pull:`12043` for a comparison with pytest 8.0 and <8. + + +- `#12011 `_: Fixed a regression in 8.0.1 whereby ``setup_module`` xunit-style fixtures are not executed when ``--doctest-modules`` is passed. + + +- `#12014 `_: Fix the ``stacklevel`` used when warning about marks used on fixtures. + + +- `#12039 `_: Fixed a regression in ``8.0.2`` where tests created using :fixture:`tmp_path` have been collected multiple times in CI under Windows. + + + +Improved Documentation +---------------------- + +- `#11790 `_: Documented the retention of temporary directories created using the ``tmp_path`` fixture in more detail. + + + +Trivial/Internal Changes +------------------------ + +- `#11785 `_: Some changes were made to private functions which may affect plugins which access them: + + - ``FixtureManager._getautousenames()`` now takes a ``Node`` itself instead of the nodeid. + - ``FixtureManager.getfixturedefs()`` now takes the ``Node`` itself instead of the nodeid. + - The ``_pytest.nodes.iterparentnodeids()`` function is removed without replacement. + Prefer to traverse the node hierarchy itself instead. + If you really need to, copy the function from the previous pytest release. + + pytest 8.0.2 (2024-02-24) ========================= diff --git a/doc/en/example/parametrize.rst b/doc/en/example/parametrize.rst index c6ac64899..85c683679 100644 --- a/doc/en/example/parametrize.rst +++ b/doc/en/example/parametrize.rst @@ -162,7 +162,7 @@ objects, they are still using the default pytest representation: rootdir: /home/sweet/project collected 8 items - + @@ -239,7 +239,7 @@ If you just collect tests you'll also nicely see 'advanced' and 'basic' as varia rootdir: /home/sweet/project collected 4 items - + @@ -318,7 +318,7 @@ Let's first see how it looks like at collection time: rootdir: /home/sweet/project collected 2 items - + diff --git a/doc/en/example/pythoncollection.rst b/doc/en/example/pythoncollection.rst index 7207ca2ae..6822aa68e 100644 --- a/doc/en/example/pythoncollection.rst +++ b/doc/en/example/pythoncollection.rst @@ -152,7 +152,7 @@ The test collection would look like this: configfile: pytest.ini collected 2 items - + @@ -215,7 +215,7 @@ You can always peek at the collection tree without running tests like this: configfile: pytest.ini collected 3 items - + diff --git a/doc/en/example/reportingdemo.rst b/doc/en/example/reportingdemo.rst index 2e8d4824c..2c34cc2b0 100644 --- a/doc/en/example/reportingdemo.rst +++ b/doc/en/example/reportingdemo.rst @@ -445,7 +445,7 @@ Here is a nice run of several failures and how ``pytest`` presents things: self = def test_tupleerror(self): - > a, b = [1] # NOQA + > a, b = [1] # noqa: F841 E ValueError: not enough values to unpack (expected 2, got 1) failure_demo.py:175: ValueError @@ -467,7 +467,7 @@ Here is a nice run of several failures and how ``pytest`` presents things: self = def test_some_error(self): - > if namenotexi: # NOQA + > if namenotexi: # noqa: F821 E NameError: name 'namenotexi' is not defined failure_demo.py:183: NameError diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst index f19198864..89381c8c7 100644 --- a/doc/en/getting-started.rst +++ b/doc/en/getting-started.rst @@ -22,7 +22,7 @@ Install ``pytest`` .. code-block:: bash $ pytest --version - pytest 8.0.2 + pytest 8.1.0 .. _`simpletest`: diff --git a/doc/en/how-to/fixtures.rst b/doc/en/how-to/fixtures.rst index 329c568c0..c32de1610 100644 --- a/doc/en/how-to/fixtures.rst +++ b/doc/en/how-to/fixtures.rst @@ -1418,7 +1418,7 @@ Running the above tests results in the following test IDs being used: rootdir: /home/sweet/project collected 12 items - + diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index f84b7ea48..358f371e5 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -2103,6 +2103,8 @@ All the command-line flags can be obtained by running ``pytest --help``:: --log-cli-date-format=LOG_CLI_DATE_FORMAT Log date format used by the logging module --log-file=LOG_FILE Path to a file when logging will be written to + --log-file-mode={w,a} + Log file open mode --log-file-level=LOG_FILE_LEVEL Log file logging level --log-file-format=LOG_FILE_FORMAT @@ -2128,6 +2130,9 @@ All the command-line flags can be obtained by running ``pytest --help``:: Each line specifies a pattern for warnings.filterwarnings. Processed after -W/--pythonwarnings. + consider_namespace_packages (bool): + Consider namespace packages when resolving module + names during import usefixtures (args): List of default fixtures to be used with this project python_files (args): Glob-style file patterns for Python test module @@ -2146,6 +2151,11 @@ All the command-line flags can be obtained by running ``pytest --help``:: progress information ("progress" (percentage) | "count" | "progress-even-when-capture-no" (forces progress even when capture=no) + verbosity_test_cases (string): + Specify a verbosity level for test case execution, + overriding the main level. Higher levels will + provide more detailed information about each test + case executed. xfail_strict (bool): Default for the strict parameter of xfail markers when not given explicitly (default: False) tmp_path_retention_count (string): @@ -2193,6 +2203,8 @@ All the command-line flags can be obtained by running ``pytest --help``:: log_cli_date_format (string): Default value for --log-cli-date-format log_file (string): Default value for --log-file + log_file_mode (string): + Default value for --log-file-mode log_file_level (string): Default value for --log-file-level log_file_format (string):