From 5cd0535395541d8940035418b368331318002199 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 17 Jan 2024 22:53:04 +0200 Subject: [PATCH 1/4] testing: temporarily disable test due to hypothesis issue (#11836) Ref: https://github.com/pytest-dev/pytest/pull/11825#issuecomment-1894094641 --- testing/python/metafunc.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index 9768c82ff..9393c9727 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -13,9 +13,6 @@ from typing import Sequence from typing import Tuple from typing import Union -import hypothesis -from hypothesis import strategies - import pytest from _pytest import fixtures from _pytest import python @@ -27,6 +24,9 @@ from _pytest.python import Function from _pytest.python import IdMaker from _pytest.scope import Scope +# import hypothesis +# from hypothesis import strategies + class TestMetafunc: def Metafunc(self, func, config=None) -> python.Metafunc: @@ -292,14 +292,15 @@ class TestMetafunc: assert metafunc._calls[2].id == "x1-a" assert metafunc._calls[3].id == "x1-b" - @hypothesis.given(strategies.text() | strategies.binary()) - @hypothesis.settings( - deadline=400.0 - ) # very close to std deadline and CI boxes are not reliable in CPU power - def test_idval_hypothesis(self, value) -> None: - escaped = IdMaker([], [], None, None, None, None, None)._idval(value, "a", 6) - assert isinstance(escaped, str) - escaped.encode("ascii") + # TODO: Uncomment - https://github.com/HypothesisWorks/hypothesis/pull/3849 + # @hypothesis.given(strategies.text() | strategies.binary()) + # @hypothesis.settings( + # deadline=400.0 + # ) # very close to std deadline and CI boxes are not reliable in CPU power + # def test_idval_hypothesis(self, value) -> None: + # escaped = IdMaker([], [], None, None, None, None, None)._idval(value, "a", 6) + # assert isinstance(escaped, str) + # escaped.encode("ascii") def test_unicode_idval(self) -> None: """Test that Unicode strings outside the ASCII character set get From ca5bbd0a9f56c8f9b3f5a43c47ff11c360f33d0b Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Wed, 17 Jan 2024 23:44:01 +0200 Subject: [PATCH 2/4] Merge pull request #11835 from pytest-dev/release-8.0.0rc2 Prepare release version 8.0.0rc2 (cherry picked from commit 97960bdd148972b2f26bd9b336163e590bbc4c6b) --- changelog/11233.feature.rst | 5 ----- changelog/11706.bugfix.rst | 1 - changelog/11758.bugfix.rst | 2 -- changelog/11825.improvement.rst | 1 - changelog/9765.bugfix.rst | 3 --- doc/en/announce/index.rst | 1 + doc/en/announce/release-8.0.0rc2.rst | 32 ++++++++++++++++++++++++++++ doc/en/changelog.rst | 31 +++++++++++++++++++++++++++ doc/en/example/parametrize.rst | 10 ++++----- doc/en/example/pythoncollection.rst | 4 ++-- doc/en/example/simple.rst | 25 ++++++++++++++++++++++ doc/en/getting-started.rst | 2 +- doc/en/how-to/fixtures.rst | 2 +- doc/en/how-to/output.rst | 11 +++++++++- 14 files changed, 108 insertions(+), 22 deletions(-) delete mode 100644 changelog/11233.feature.rst delete mode 100644 changelog/11706.bugfix.rst delete mode 100644 changelog/11758.bugfix.rst delete mode 100644 changelog/11825.improvement.rst delete mode 100644 changelog/9765.bugfix.rst create mode 100644 doc/en/announce/release-8.0.0rc2.rst diff --git a/changelog/11233.feature.rst b/changelog/11233.feature.rst deleted file mode 100644 index c465def84..000000000 --- a/changelog/11233.feature.rst +++ /dev/null @@ -1,5 +0,0 @@ -Improvements to how ``-r`` for xfailures and xpasses: - -* Report tracebacks for xfailures when ``-rx`` is set. -* Report captured output for xpasses when ``-rX`` is set. -* For xpasses, add ``-`` in summary between test name and reason, to match how xfail is displayed. diff --git a/changelog/11706.bugfix.rst b/changelog/11706.bugfix.rst deleted file mode 100644 index 1b90d8f0b..000000000 --- a/changelog/11706.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fix reporting of teardown errors in higher-scoped fixtures when using `--maxfail` or `--stepwise`. diff --git a/changelog/11758.bugfix.rst b/changelog/11758.bugfix.rst deleted file mode 100644 index af8a3f351..000000000 --- a/changelog/11758.bugfix.rst +++ /dev/null @@ -1,2 +0,0 @@ -Fixed ``IndexError: string index out of range`` crash in ``if highlighted[-1] == "\n" and source[-1] != "\n"``. -This bug was introduced in pytest 8.0.0rc1. diff --git a/changelog/11825.improvement.rst b/changelog/11825.improvement.rst deleted file mode 100644 index afd85a041..000000000 --- a/changelog/11825.improvement.rst +++ /dev/null @@ -1 +0,0 @@ -The :hook:`pytest_plugin_registered` hook has a new ``plugin_name`` parameter containing the name by which ``plugin`` is registered. diff --git a/changelog/9765.bugfix.rst b/changelog/9765.bugfix.rst deleted file mode 100644 index c726cbf8d..000000000 --- a/changelog/9765.bugfix.rst +++ /dev/null @@ -1,3 +0,0 @@ -Fixed a frustrating bug that afflicted some users with the only error being ``assert mod not in mods``. The issue was caused by the fact that ``str(Path(mod))`` and ``mod.__file__`` don't necessarily produce the same string, and was being erroneously used interchangably in some places in the code. - -This fix also broke the internal API of ``PytestPluginManager.consider_conftest`` by introducing a new parameter -- we mention this in case it is being used by external code, even if marked as *private*. diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst index 740767c01..1c413de7a 100644 --- a/doc/en/announce/index.rst +++ b/doc/en/announce/index.rst @@ -6,6 +6,7 @@ Release announcements :maxdepth: 2 + release-8.0.0rc2 release-8.0.0rc1 release-7.4.4 release-7.4.3 diff --git a/doc/en/announce/release-8.0.0rc2.rst b/doc/en/announce/release-8.0.0rc2.rst new file mode 100644 index 000000000..1a6444c52 --- /dev/null +++ b/doc/en/announce/release-8.0.0rc2.rst @@ -0,0 +1,32 @@ +pytest-8.0.0rc2 +======================================= + +The pytest team is proud to announce the 8.0.0rc2 prerelease! + +This is a prerelease, not intended for production use, but to test the upcoming features and improvements +in order to catch any major problems before the final version is released to the major public. + +We appreciate your help testing this out before the final release, making sure to report any +regressions to our issue tracker: + +https://github.com/pytest-dev/pytest/issues + +When doing so, please include the string ``[prerelease]`` in the title. + +You can upgrade from PyPI via: + + pip install pytest==8.0.0rc2 + +Users are encouraged to take a look at the CHANGELOG carefully: + + https://docs.pytest.org/en/release-8.0.0rc2/changelog.html + +Thanks to all the contributors to this release: + +* Ben Brown +* Bruno Oliveira +* Ran Benita + + +Happy testing, +The pytest Development Team diff --git a/doc/en/changelog.rst b/doc/en/changelog.rst index 755f386c6..da275b622 100644 --- a/doc/en/changelog.rst +++ b/doc/en/changelog.rst @@ -28,6 +28,37 @@ with advance notice in the **Deprecations** section of releases. .. towncrier release notes start +pytest 8.0.0rc2 (2024-01-17) +============================ + + +Improvements +------------ + +- `#11233 `_: Improvements to ``-r`` for xfailures and xpasses: + + * Report tracebacks for xfailures when ``-rx`` is set. + * Report captured output for xpasses when ``-rX`` is set. + * For xpasses, add ``-`` in summary between test name and reason, to match how xfail is displayed. + +- `#11825 `_: The :hook:`pytest_plugin_registered` hook has a new ``plugin_name`` parameter containing the name by which ``plugin`` is registered. + + +Bug Fixes +--------- + +- `#11706 `_: Fix reporting of teardown errors in higher-scoped fixtures when using `--maxfail` or `--stepwise`. + + +- `#11758 `_: Fixed ``IndexError: string index out of range`` crash in ``if highlighted[-1] == "\n" and source[-1] != "\n"``. + This bug was introduced in pytest 8.0.0rc1. + + +- `#9765 `_, `#11816 `_: Fixed a frustrating bug that afflicted some users with the only error being ``assert mod not in mods``. The issue was caused by the fact that ``str(Path(mod))`` and ``mod.__file__`` don't necessarily produce the same string, and was being erroneously used interchangably in some places in the code. + + This fix also broke the internal API of ``PytestPluginManager.consider_conftest`` by introducing a new parameter -- we mention this in case it is being used by external code, even if marked as *private*. + + pytest 8.0.0rc1 (2023-12-30) ============================ diff --git a/doc/en/example/parametrize.rst b/doc/en/example/parametrize.rst index 0426266e5..9d78fc403 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 - + @@ -503,10 +503,10 @@ Running it results in some skips if we don't have all the python interpreters in .. code-block:: pytest . $ pytest -rs -q multipython.py - ssssssssssss...ssssssssssss [100%] + ssssssssssssssssssssssss... [100%] ========================= short test summary info ========================== SKIPPED [12] multipython.py:68: 'python3.9' not found - SKIPPED [12] multipython.py:68: 'python3.11' not found + SKIPPED [12] multipython.py:68: 'python3.10' not found 3 passed, 24 skipped in 0.12s Parametrization of optional implementations/imports diff --git a/doc/en/example/pythoncollection.rst b/doc/en/example/pythoncollection.rst index dbc2c239f..e98f1a752 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/simple.rst b/doc/en/example/simple.rst index 21e5f4a09..7064f61f0 100644 --- a/doc/en/example/simple.rst +++ b/doc/en/example/simple.rst @@ -660,6 +660,31 @@ If we run this: E assert 0 test_step.py:11: AssertionError + ================================ XFAILURES ================================= + ______________________ TestUserHandling.test_deletion ______________________ + + item = + + def pytest_runtest_setup(item): + if "incremental" in item.keywords: + # retrieve the class name of the test + cls_name = str(item.cls) + # check if a previous test has failed for this class + if cls_name in _test_failed_incremental: + # retrieve the index of the test (if parametrize is used in combination with incremental) + parametrize_index = ( + tuple(item.callspec.indices.values()) + if hasattr(item, "callspec") + else () + ) + # retrieve the name of the first test function to fail for this class name and index + test_name = _test_failed_incremental[cls_name].get(parametrize_index, None) + # if name found, test has failed for the combination of class name & test name + if test_name is not None: + > pytest.xfail(f"previous test failed ({test_name})") + E _pytest.outcomes.XFailed: previous test failed (test_modification) + + conftest.py:47: XFailed ========================= short test summary info ========================== XFAIL test_step.py::TestUserHandling::test_deletion - reason: previous test failed (test_modification) ================== 1 failed, 2 passed, 1 xfailed in 0.12s ================== diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst index 0f74a8ecf..90765df60 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.0rc1 + pytest 8.0.0rc2 .. _`simpletest`: diff --git a/doc/en/how-to/fixtures.rst b/doc/en/how-to/fixtures.rst index 95c376fd3..e3209c777 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 95c3a89b5..76b2a53dd 100644 --- a/doc/en/how-to/output.rst +++ b/doc/en/how-to/output.rst @@ -404,10 +404,19 @@ Example: E assert 0 test_example.py:14: AssertionError + ================================ XFAILURES ================================= + ________________________________ test_xfail ________________________________ + + def test_xfail(): + > pytest.xfail("xfailing this test") + E _pytest.outcomes.XFailed: xfailing this test + + test_example.py:26: XFailed + ================================= XPASSES ================================== ========================= short test summary info ========================== SKIPPED [1] test_example.py:22: skipping this test XFAIL test_example.py::test_xfail - reason: xfailing this test - XPASS test_example.py::test_xpass always xfail + XPASS test_example.py::test_xpass - always xfail ERROR test_example.py::test_error - assert 0 FAILED test_example.py::test_fail - assert 0 == 1 failed, 1 passed, 1 skipped, 1 xfailed, 1 xpassed, 1 error in 0.12s === From 7fd561e4ba5dd5ae7a04c7b92b83cef8492a358d Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 17 Jan 2024 19:11:10 -0300 Subject: [PATCH 3/4] Properly attach packages to the GH release notes (#11839) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow up to https://github.com/pytest-dev/pytest/pull/11754, noticed that the latest GitHub release does not contain the attached files. Output log from the action: ``` 🤔 Pattern 'dist/*' does not match any files. ``` --- .github/workflows/deploy.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 585398ba3..5d5015f18 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -72,6 +72,12 @@ jobs: fetch-depth: 0 persist-credentials: false + - name: Download Package + uses: actions/download-artifact@v4 + with: + name: Packages + path: dist + - name: Set up Python uses: actions/setup-python@v5 with: From eefc9d47fc40a9d5971a6207689c50efb1555a95 Mon Sep 17 00:00:00 2001 From: faph Date: Thu, 18 Jan 2024 10:21:49 +0000 Subject: [PATCH 4/4] [DOCS] Clarify tmp_path directory location and retention (#11830) Fixes #11789 and #11790 --- AUTHORS | 1 + changelog/11790.doc.rst | 1 + doc/en/how-to/tmp_path.rst | 22 +++++++++++++--------- src/_pytest/legacypath.py | 4 ++-- src/_pytest/tmpdir.py | 4 ++-- 5 files changed, 19 insertions(+), 13 deletions(-) create mode 100644 changelog/11790.doc.rst diff --git a/AUTHORS b/AUTHORS index 353489b6c..803bb2b18 100644 --- a/AUTHORS +++ b/AUTHORS @@ -141,6 +141,7 @@ Evgeny Seliverstov Fabian Sturm Fabien Zarifian Fabio Zadrozny +faph Felix Hofstätter Felix Nieuwenhuizen Feng Ma diff --git a/changelog/11790.doc.rst b/changelog/11790.doc.rst new file mode 100644 index 000000000..648b20b96 --- /dev/null +++ b/changelog/11790.doc.rst @@ -0,0 +1 @@ +Documented the retention of temporary directories created using the ``tmp_path`` fixture in more detail. diff --git a/doc/en/how-to/tmp_path.rst b/doc/en/how-to/tmp_path.rst index 3e680dcac..3cc5152e9 100644 --- a/doc/en/how-to/tmp_path.rst +++ b/doc/en/how-to/tmp_path.rst @@ -8,9 +8,8 @@ How to use temporary directories and files in tests The ``tmp_path`` fixture ------------------------ -You can use the ``tmp_path`` fixture which will -provide a temporary directory unique to the current test, -created in the `base temporary directory`_. +You can use the ``tmp_path`` fixture which will provide a temporary directory +unique to each test function. ``tmp_path`` is a :class:`pathlib.Path` object. Here is an example test usage: @@ -62,6 +61,11 @@ Running this would result in a passed test except for the last FAILED test_tmp_path.py::test_create_file - assert 0 ============================ 1 failed in 0.12s ============================= +By default, ``pytest`` retains the temporary directory for the last 3 ``pytest`` +invocations. Concurrent invocations of the same test function are supported by +configuring the base temporary directory to be unique for each concurrent +run. See `temporary directory location and retention`_ for details. + .. _`tmp_path_factory example`: The ``tmp_path_factory`` fixture @@ -100,7 +104,7 @@ See :ref:`tmp_path_factory API ` for details. .. _tmpdir: The ``tmpdir`` and ``tmpdir_factory`` fixtures ---------------------------------------------------- +---------------------------------------------- The ``tmpdir`` and ``tmpdir_factory`` fixtures are similar to ``tmp_path`` and ``tmp_path_factory``, but use/return legacy `py.path.local`_ objects @@ -124,10 +128,10 @@ See :fixture:`tmpdir ` :fixture:`tmpdir_factory ` API for details. -.. _`base temporary directory`: +.. _`temporary directory location and retention`: -The default base temporary directory ------------------------------------------------ +Temporary directory location and retention +------------------------------------------ Temporary directories are by default created as sub-directories of the system temporary directory. The base name will be ``pytest-NUM`` where @@ -152,7 +156,7 @@ You can override the default temporary directory setting like this: for that purpose only. When distributing tests on the local machine using ``pytest-xdist``, care is taken to -automatically configure a basetemp directory for the sub processes such that all temporary -data lands below a single per-test run basetemp directory. +automatically configure a `basetemp` directory for the sub processes such that all temporary +data lands below a single per-test run temporary directory. .. _`py.path.local`: https://py.readthedocs.io/en/latest/path.html diff --git a/src/_pytest/legacypath.py b/src/_pytest/legacypath.py index b2dd87436..f69315b5f 100644 --- a/src/_pytest/legacypath.py +++ b/src/_pytest/legacypath.py @@ -326,8 +326,8 @@ class LegacyTmpdirPlugin: 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. diff --git a/src/_pytest/tmpdir.py b/src/_pytest/tmpdir.py index 6fa227760..21e5366a3 100644 --- a/src/_pytest/tmpdir.py +++ b/src/_pytest/tmpdir.py @@ -262,8 +262,8 @@ def tmp_path( 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. """