From 79ca819e59948661c5403dd4aa77c248266a8c76 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 27 Apr 2024 20:35:29 -0300 Subject: [PATCH] Merge pull request #12257 from pytest-dev/release-8.2.0 Prepare release 8.2.0 (cherry picked from commit 69c3bcea36e1cf3468ac3cb92da9cf37038f959d) --- changelog/11523.improvement.rst | 5 -- changelog/11728.improvement.rst | 1 - changelog/11777.improvement.rst | 1 - changelog/11871.feature.rst | 1 - changelog/12065.bugfix.rst | 4 -- changelog/12069.deprecation.rst | 12 ----- changelog/12069.trivial.rst | 1 - changelog/12112.improvement.rst | 1 - changelog/12135.bugfix.rst | 1 - changelog/12167.trivial.rst | 1 - changelog/12194.bugfix.rst | 1 - changelog/1489.bugfix.rst | 1 - changelog/9502.improvement.rst | 1 - doc/en/announce/index.rst | 1 + doc/en/announce/release-8.2.0.rst | 43 +++++++++++++++ doc/en/builtin.rst | 30 +++++------ doc/en/changelog.rst | 81 +++++++++++++++++++++++++++++ doc/en/example/parametrize.rst | 6 +-- doc/en/example/pythoncollection.rst | 4 +- doc/en/getting-started.rst | 2 +- doc/en/how-to/fixtures.rst | 2 +- doc/en/how-to/output.rst | 44 ++++++++++++++-- 22 files changed, 188 insertions(+), 56 deletions(-) delete mode 100644 changelog/11523.improvement.rst delete mode 100644 changelog/11728.improvement.rst delete mode 100644 changelog/11777.improvement.rst delete mode 100644 changelog/11871.feature.rst delete mode 100644 changelog/12065.bugfix.rst delete mode 100644 changelog/12069.deprecation.rst delete mode 100644 changelog/12069.trivial.rst delete mode 100644 changelog/12112.improvement.rst delete mode 100644 changelog/12135.bugfix.rst delete mode 100644 changelog/12167.trivial.rst delete mode 100644 changelog/12194.bugfix.rst delete mode 100644 changelog/1489.bugfix.rst delete mode 100644 changelog/9502.improvement.rst create mode 100644 doc/en/announce/release-8.2.0.rst diff --git a/changelog/11523.improvement.rst b/changelog/11523.improvement.rst deleted file mode 100644 index f7d8ff89d..000000000 --- a/changelog/11523.improvement.rst +++ /dev/null @@ -1,5 +0,0 @@ -:func:`pytest.importorskip` will now issue a warning if the module could be found, but raised :class:`ImportError` instead of :class:`ModuleNotFoundError`. - -The warning can be suppressed by passing ``exc_type=ImportError`` to :func:`pytest.importorskip`. - -See :ref:`import-or-skip-import-error` for details. diff --git a/changelog/11728.improvement.rst b/changelog/11728.improvement.rst deleted file mode 100644 index 1e87fc5ed..000000000 --- a/changelog/11728.improvement.rst +++ /dev/null @@ -1 +0,0 @@ -For ``unittest``-based tests, exceptions during class cleanup (as raised by functions registered with :meth:`TestCase.addClassCleanup `) are now reported instead of silently failing. diff --git a/changelog/11777.improvement.rst b/changelog/11777.improvement.rst deleted file mode 100644 index fb53c63c1..000000000 --- a/changelog/11777.improvement.rst +++ /dev/null @@ -1 +0,0 @@ -Text is no longer truncated in the ``short test summary info`` section when ``-vv`` is given. diff --git a/changelog/11871.feature.rst b/changelog/11871.feature.rst deleted file mode 100644 index 530db8c3c..000000000 --- a/changelog/11871.feature.rst +++ /dev/null @@ -1 +0,0 @@ -Added support for reading command line arguments from a file using the prefix character ``@``, like e.g.: ``pytest @tests.txt``. The file must have one argument per line. diff --git a/changelog/12065.bugfix.rst b/changelog/12065.bugfix.rst deleted file mode 100644 index ca55b327e..000000000 --- a/changelog/12065.bugfix.rst +++ /dev/null @@ -1,4 +0,0 @@ -Fixed a regression in pytest 8.0.0 where test classes containing ``setup_method`` and tests using ``@staticmethod`` or ``@classmethod`` would crash with ``AttributeError: 'NoneType' object has no attribute 'setup_method'``. - -Now the :attr:`request.instance ` attribute of tests using ``@staticmethod`` and ``@classmethod`` is no longer ``None``, but a fresh instance of the class, like in non-static methods. -Previously it was ``None``, and all fixtures of such tests would share a single ``self``. diff --git a/changelog/12069.deprecation.rst b/changelog/12069.deprecation.rst deleted file mode 100644 index c8798b5ff..000000000 --- a/changelog/12069.deprecation.rst +++ /dev/null @@ -1,12 +0,0 @@ -A deprecation warning is now raised when implementations of one of the following hooks request a deprecated ``py.path.local`` parameter instead of the ``pathlib.Path`` parameter which replaced it: - -- :hook:`pytest_ignore_collect` - the ``path`` parameter - use ``collection_path`` instead. -- :hook:`pytest_collect_file` - the ``path`` parameter - use ``file_path`` instead. -- :hook:`pytest_pycollect_makemodule` - the ``path`` parameter - use ``module_path`` instead. -- :hook:`pytest_report_header` - the ``startdir`` parameter - use ``start_path`` instead. -- :hook:`pytest_report_collectionfinish` - the ``startdir`` parameter - use ``start_path`` instead. - -The replacement parameters are available since pytest 7.0.0. -The old parameters will be removed in pytest 9.0.0. - -See :ref:`legacy-path-hooks-deprecated` for more details. diff --git a/changelog/12069.trivial.rst b/changelog/12069.trivial.rst deleted file mode 100644 index 8eb9b0c46..000000000 --- a/changelog/12069.trivial.rst +++ /dev/null @@ -1 +0,0 @@ -``pluggy>=1.5.0`` is now required. diff --git a/changelog/12112.improvement.rst b/changelog/12112.improvement.rst deleted file mode 100644 index 3f997b2af..000000000 --- a/changelog/12112.improvement.rst +++ /dev/null @@ -1 +0,0 @@ -Improve namespace packages detection when :confval:`consider_namespace_packages` is enabled, covering more situations (like editable installs). diff --git a/changelog/12135.bugfix.rst b/changelog/12135.bugfix.rst deleted file mode 100644 index 734733b10..000000000 --- a/changelog/12135.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fix fixtures adding their finalizer multiple times to fixtures they request, causing unreliable and non-intuitive teardown ordering in some instances. diff --git a/changelog/12167.trivial.rst b/changelog/12167.trivial.rst deleted file mode 100644 index da9363420..000000000 --- a/changelog/12167.trivial.rst +++ /dev/null @@ -1 +0,0 @@ -cache: create cache directory supporting files (``CACHEDIR.TAG``, ``.gitignore``, etc.) in a temporary directory to provide atomic semantics. diff --git a/changelog/12194.bugfix.rst b/changelog/12194.bugfix.rst deleted file mode 100644 index 6983ba35a..000000000 --- a/changelog/12194.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fixed a bug with ``--importmode=importlib`` and ``--doctest-modules`` where child modules did not appear as attributes in parent modules. diff --git a/changelog/1489.bugfix.rst b/changelog/1489.bugfix.rst deleted file mode 100644 index 70c5dd125..000000000 --- a/changelog/1489.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fix some instances where teardown of higher-scoped fixtures was not happening in the reverse order they were initialized in. diff --git a/changelog/9502.improvement.rst b/changelog/9502.improvement.rst deleted file mode 100644 index 2eaf6a727..000000000 --- a/changelog/9502.improvement.rst +++ /dev/null @@ -1 +0,0 @@ -Added :envvar:`PYTEST_VERSION` environment variable which is defined at the start of the pytest session and undefined afterwards. It contains the value of ``pytest.__version__``, and among other things can be used to easily check if code is running from within a pytest run. diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst index bb39eb7e6..4d0a3ab55 100644 --- a/doc/en/announce/index.rst +++ b/doc/en/announce/index.rst @@ -6,6 +6,7 @@ Release announcements :maxdepth: 2 + release-8.2.0 release-8.1.2 release-8.1.1 release-8.1.0 diff --git a/doc/en/announce/release-8.2.0.rst b/doc/en/announce/release-8.2.0.rst new file mode 100644 index 000000000..2a63c8d87 --- /dev/null +++ b/doc/en/announce/release-8.2.0.rst @@ -0,0 +1,43 @@ +pytest-8.2.0 +======================================= + +The pytest team is proud to announce the 8.2.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: + +* Bruno Oliveira +* Daniel Miller +* Florian Bruhin +* HolyMagician03-UMich +* John Litborn +* Levon Saldamli +* Linghao Zhang +* Manuel López-Ibáñez +* Pierre Sassoulas +* Ran Benita +* Ronny Pfannschmidt +* Sebastian Meyer +* Shekhar verma +* Tamir Duberstein +* Tobias Stoeckmann +* dj +* jakkdl +* poulami-sau +* tserg + + +Happy testing, +The pytest Development Team diff --git a/doc/en/builtin.rst b/doc/en/builtin.rst index 9d49389f1..d5f2e9a1b 100644 --- a/doc/en/builtin.rst +++ b/doc/en/builtin.rst @@ -22,7 +22,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a cachedir: .pytest_cache rootdir: /home/sweet/project collected 0 items - cache -- .../_pytest/cacheprovider.py:527 + cache -- .../_pytest/cacheprovider.py:542 Return a cache object that can persist state between testing sessions. cache.get(key, default) @@ -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:1008 + capsysbinary -- .../_pytest/capture.py:1003 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:1035 + capfd -- .../_pytest/capture.py:1030 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:1062 + capfdbinary -- .../_pytest/capture.py:1057 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:981 + capsys -- .../_pytest/capture.py:976 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:737 + doctest_namespace [session scope] -- .../_pytest/doctest.py:738 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:1346 + pytestconfig [session scope] -- .../_pytest/fixtures.py:1335 Session-scoped fixture that returns the session's :class:`pytest.Config` object. @@ -125,7 +125,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a if pytestconfig.getoption("verbose") > 0: ... - record_property -- .../_pytest/junitxml.py:283 + record_property -- .../_pytest/junitxml.py:284 Add extra properties to the calling test. User properties become part of the test report and are available to the @@ -139,13 +139,13 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a def test_function(record_property): record_property("example_key", 1) - record_xml_attribute -- .../_pytest/junitxml.py:306 + record_xml_attribute -- .../_pytest/junitxml.py:307 Add extra xml attributes to the tag for the calling test. The fixture is callable with ``name, value``. The value is automatically XML-encoded. - record_testsuite_property [session scope] -- .../_pytest/junitxml.py:344 + record_testsuite_property [session scope] -- .../_pytest/junitxml.py:345 Record a new ```` tag as child of the root ````. This is suitable to writing global information regarding the entire test @@ -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:601 + caplog -- .../_pytest/logging.py:602 Access and control log capturing. Captured logs are available through the following properties/methods:: @@ -203,7 +203,7 @@ For information about fixtures, see :ref:`fixtures`. To see a complete list of a * caplog.record_tuples -> list of (logger_name, level, message) tuples * caplog.clear() -> clear captured records and formatted log output string - monkeypatch -- .../_pytest/monkeypatch.py:32 + monkeypatch -- .../_pytest/monkeypatch.py:33 A convenient fixture for monkey-patching. The fixture provides these methods to modify objects, dictionaries, or @@ -227,16 +227,16 @@ 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:31 + recwarn -- .../_pytest/recwarn.py:32 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 on warning categories. - tmp_path_factory [session scope] -- .../_pytest/tmpdir.py:241 + tmp_path_factory [session scope] -- .../_pytest/tmpdir.py:242 Return a :class:`pytest.TempPathFactory` instance for the test session. - tmp_path -- .../_pytest/tmpdir.py:256 + tmp_path -- .../_pytest/tmpdir.py:257 Return a temporary directory path object which is unique to each test function invocation, created as a sub directory of the base temporary directory. diff --git a/doc/en/changelog.rst b/doc/en/changelog.rst index fb316e706..2630d95cf 100644 --- a/doc/en/changelog.rst +++ b/doc/en/changelog.rst @@ -28,6 +28,87 @@ with advance notice in the **Deprecations** section of releases. .. towncrier release notes start +pytest 8.2.0 (2024-04-27) +========================= + +Deprecations +------------ + +- `#12069 `_: A deprecation warning is now raised when implementations of one of the following hooks request a deprecated ``py.path.local`` parameter instead of the ``pathlib.Path`` parameter which replaced it: + + - :hook:`pytest_ignore_collect` - the ``path`` parameter - use ``collection_path`` instead. + - :hook:`pytest_collect_file` - the ``path`` parameter - use ``file_path`` instead. + - :hook:`pytest_pycollect_makemodule` - the ``path`` parameter - use ``module_path`` instead. + - :hook:`pytest_report_header` - the ``startdir`` parameter - use ``start_path`` instead. + - :hook:`pytest_report_collectionfinish` - the ``startdir`` parameter - use ``start_path`` instead. + + The replacement parameters are available since pytest 7.0.0. + The old parameters will be removed in pytest 9.0.0. + + See :ref:`legacy-path-hooks-deprecated` for more details. + + + +Features +-------- + +- `#11871 `_: Added support for reading command line arguments from a file using the prefix character ``@``, like e.g.: ``pytest @tests.txt``. The file must have one argument per line. + + See :ref:`Read arguments from file ` for details. + + + +Improvements +------------ + +- `#11523 `_: :func:`pytest.importorskip` will now issue a warning if the module could be found, but raised :class:`ImportError` instead of :class:`ModuleNotFoundError`. + + The warning can be suppressed by passing ``exc_type=ImportError`` to :func:`pytest.importorskip`. + + See :ref:`import-or-skip-import-error` for details. + + +- `#11728 `_: For ``unittest``-based tests, exceptions during class cleanup (as raised by functions registered with :meth:`TestCase.addClassCleanup `) are now reported instead of silently failing. + + +- `#11777 `_: Text is no longer truncated in the ``short test summary info`` section when ``-vv`` is given. + + +- `#12112 `_: Improved namespace packages detection when :confval:`consider_namespace_packages` is enabled, covering more situations (like editable installs). + + +- `#9502 `_: Added :envvar:`PYTEST_VERSION` environment variable which is defined at the start of the pytest session and undefined afterwards. It contains the value of ``pytest.__version__``, and among other things can be used to easily check if code is running from within a pytest run. + + + +Bug Fixes +--------- + +- `#12065 `_: Fixed a regression in pytest 8.0.0 where test classes containing ``setup_method`` and tests using ``@staticmethod`` or ``@classmethod`` would crash with ``AttributeError: 'NoneType' object has no attribute 'setup_method'``. + + Now the :attr:`request.instance ` attribute of tests using ``@staticmethod`` and ``@classmethod`` is no longer ``None``, but a fresh instance of the class, like in non-static methods. + Previously it was ``None``, and all fixtures of such tests would share a single ``self``. + + +- `#12135 `_: Fixed issue where fixtures adding their finalizer multiple times to fixtures they request would cause unreliable and non-intuitive teardown ordering in some instances. + + +- `#12194 `_: Fixed a bug with ``--importmode=importlib`` and ``--doctest-modules`` where child modules did not appear as attributes in parent modules. + + +- `#1489 `_: Fixed some instances where teardown of higher-scoped fixtures was not happening in the reverse order they were initialized in. + + + +Trivial/Internal Changes +------------------------ + +- `#12069 `_: ``pluggy>=1.5.0`` is now required. + + +- `#12167 `_: :ref:`cache `: create supporting files (``CACHEDIR.TAG``, ``.gitignore``, etc.) in a temporary directory to provide atomic semantics. + + pytest 8.1.2 (2024-04-26) ========================= diff --git a/doc/en/example/parametrize.rst b/doc/en/example/parametrize.rst index 672c7c445..1bbe2faaa 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 c01e685f3..a383173d0 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/getting-started.rst b/doc/en/getting-started.rst index e96eabbc5..5b33e308d 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.1.2 + pytest 8.2.0 .. _`simpletest`: diff --git a/doc/en/how-to/fixtures.rst b/doc/en/how-to/fixtures.rst index ba416ccbc..72b69a146 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/how-to/output.rst b/doc/en/how-to/output.rst index 5b47a5c77..7a4e32edc 100644 --- a/doc/en/how-to/output.rst +++ b/doc/en/how-to/output.rst @@ -294,9 +294,47 @@ Now if we increase verbosity even more: test_verbosity_example.py:19: AssertionError ========================= short test summary info ========================== - FAILED test_verbosity_example.py::test_words_fail - AssertionError: asser... - FAILED test_verbosity_example.py::test_numbers_fail - AssertionError: ass... - FAILED test_verbosity_example.py::test_long_text_fail - AssertionError: a... + FAILED test_verbosity_example.py::test_words_fail - AssertionError: assert ['banana', 'apple', 'grapes', 'melon', 'kiwi'] == ['banana', 'apple', 'orange', 'melon', 'kiwi'] + + At index 2 diff: 'grapes' != 'orange' + + Full diff: + [ + 'banana', + 'apple', + - 'orange', + ? ^ ^^ + + 'grapes', + ? ^ ^ + + 'melon', + 'kiwi', + ] + FAILED test_verbosity_example.py::test_numbers_fail - AssertionError: assert {'0': 0, '1': 1, '2': 2, '3': 3, '4': 4} == {'0': 0, '10': 10, '20': 20, '30': 30, '40': 40} + + Common items: + {'0': 0} + Left contains 4 more items: + {'1': 1, '2': 2, '3': 3, '4': 4} + Right contains 4 more items: + {'10': 10, '20': 20, '30': 30, '40': 40} + + Full diff: + { + '0': 0, + - '10': 10, + ? - - + + '1': 1, + - '20': 20, + ? - - + + '2': 2, + - '30': 30, + ? - - + + '3': 3, + - '40': 40, + ? - - + + '4': 4, + } + FAILED test_verbosity_example.py::test_long_text_fail - AssertionError: assert 'hello world' in 'Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet ' ======================= 3 failed, 1 passed in 0.12s ======================== Notice now that: