From 6c14139c9fe3418630c4d24d43d48533a14103da Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 10 Mar 2024 15:08:01 +0000 Subject: [PATCH 1/9] [8.1.x] doc/flaky: remove `box/flaky` plugin suggestion (#12102) Co-authored-by: Ran Benita --- doc/en/explanation/flaky.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/en/explanation/flaky.rst b/doc/en/explanation/flaky.rst index ccf3fbb2b0c..2beeb34e0f8 100644 --- a/doc/en/explanation/flaky.rst +++ b/doc/en/explanation/flaky.rst @@ -52,10 +52,9 @@ Plugins Rerunning any failed tests can mitigate the negative effects of flaky tests by giving them additional chances to pass, so that the overall build does not fail. Several pytest plugins support this: -* `flaky `_ -* `pytest-flakefinder `_ - `blog post `_ * `pytest-rerunfailures `_ * `pytest-replay `_: This plugin helps to reproduce locally crashes or flaky tests observed during CI runs. +* `pytest-flakefinder `_ - `blog post `_ Plugins to deliberately randomize tests can help expose tests with state problems: From cd585a1abeff52b69b98ff4cf9207a7b5efc6ce7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 11 Mar 2024 16:52:31 +0000 Subject: [PATCH 2/9] [8.1.x] doc: add versionadded to `Stash` and `StashKey` (#12109) Co-authored-by: Ran Benita --- src/_pytest/stash.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/_pytest/stash.py b/src/_pytest/stash.py index e61d75b95f7..a4b829fc6dd 100644 --- a/src/_pytest/stash.py +++ b/src/_pytest/stash.py @@ -19,6 +19,8 @@ class StashKey(Generic[T]): A ``StashKey`` is associated with the type ``T`` of the value of the key. A ``StashKey`` is unique and cannot conflict with another key. + + .. versionadded:: 7.0 """ __slots__ = () @@ -61,6 +63,8 @@ class Stash: some_str = stash[some_str_key] # The static type of some_bool is bool. some_bool = stash[some_bool_key] + + .. versionadded:: 7.0 """ __slots__ = ("_storage",) From 83614e1f3ecf5332c3dc98a55ae9939cc41948ef Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 14 Mar 2024 20:18:21 +0000 Subject: [PATCH 3/9] [8.1.x] doc: fix typos (#12119) Co-authored-by: Tobias Stoeckmann --- doc/en/conf.py | 2 +- doc/en/how-to/writing_hook_functions.rst | 2 +- doc/en/index.rst | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/en/conf.py b/doc/en/conf.py index 8059c359fc1..32ecaa17435 100644 --- a/doc/en/conf.py +++ b/doc/en/conf.py @@ -395,7 +395,7 @@ # The format is a list of tuples containing the path and title. # epub_pre_files = [] -# HTML files shat should be inserted after the pages created by sphinx. +# HTML files that should be inserted after the pages created by sphinx. # The format is a list of tuples containing the path and title. # epub_post_files = [] diff --git a/doc/en/how-to/writing_hook_functions.rst b/doc/en/how-to/writing_hook_functions.rst index 5d0a52f9d38..f4c00d04fda 100644 --- a/doc/en/how-to/writing_hook_functions.rst +++ b/doc/en/how-to/writing_hook_functions.rst @@ -100,7 +100,7 @@ object, the wrapper may modify that result, but it's probably better to avoid it If the hook implementation failed with an exception, the wrapper can handle that exception using a ``try-catch-finally`` around the ``yield``, by propagating it, -supressing it, or raising a different exception entirely. +suppressing it, or raising a different exception entirely. For more information, consult the :ref:`pluggy documentation about hook wrappers `. diff --git a/doc/en/index.rst b/doc/en/index.rst index 9d97dfaa680..08a1468986a 100644 --- a/doc/en/index.rst +++ b/doc/en/index.rst @@ -87,7 +87,7 @@ Features Documentation ------------- -* :ref:`Get started ` - install pytest and grasp its basics just twenty minutes +* :ref:`Get started ` - install pytest and grasp its basics in just twenty minutes * :ref:`How-to guides ` - step-by-step guides, covering a vast range of use-cases and needs * :ref:`Reference guides ` - includes the complete pytest API reference, lists of plugins and more * :ref:`Explanation ` - background, discussion of key topics, answers to higher-level questions From c5e3921b9fef2619a3e2c7e3e07a5cc8015005d7 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 19 Mar 2024 23:11:22 +0000 Subject: [PATCH 4/9] [8.1.x] doc: add versionadded to `ExceptionInfo.group_contains` (#12142) Co-authored-by: Sebastian Meyer --- src/_pytest/_code/code.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/_pytest/_code/code.py b/src/_pytest/_code/code.py index 12168be607c..2e3c4ba64fc 100644 --- a/src/_pytest/_code/code.py +++ b/src/_pytest/_code/code.py @@ -788,6 +788,8 @@ def group_contains( If `None`, will search for a matching exception at any nesting depth. If >= 1, will only match an exception if it's at the specified depth (depth = 1 being the exceptions contained within the topmost exception group). + + .. versionadded:: 8.0 """ msg = "Captured exception is not an instance of `BaseExceptionGroup`" assert isinstance(self.value, BaseExceptionGroup), msg From be7c8be6ce4598ad9e70ba7eccb9317bdda33c37 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 21 Mar 2024 14:37:49 +0000 Subject: [PATCH 5/9] [8.1.x] Add research item in doc (#12148) Co-authored-by: Linghao Zhang --- doc/en/explanation/flaky.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/en/explanation/flaky.rst b/doc/en/explanation/flaky.rst index 2beeb34e0f8..41cbe847989 100644 --- a/doc/en/explanation/flaky.rst +++ b/doc/en/explanation/flaky.rst @@ -105,7 +105,7 @@ This is a limited list, please submit an issue or pull request to expand it! * Gao, Zebao, Yalan Liang, Myra B. Cohen, Atif M. Memon, and Zhen Wang. "Making system user interactive tests repeatable: When and what should we control?." In *Software Engineering (ICSE), 2015 IEEE/ACM 37th IEEE International Conference on*, vol. 1, pp. 55-65. IEEE, 2015. `PDF `__ * Palomba, Fabio, and Andy Zaidman. "Does refactoring of test smells induce fixing flaky tests?." In *Software Maintenance and Evolution (ICSME), 2017 IEEE International Conference on*, pp. 1-12. IEEE, 2017. `PDF in Google Drive `__ * Bell, Jonathan, Owolabi Legunsen, Michael Hilton, Lamyaa Eloussi, Tifany Yung, and Darko Marinov. "DeFlaker: Automatically detecting flaky tests." In *Proceedings of the 2018 International Conference on Software Engineering*. 2018. `PDF `__ - +* Dutta, Saikat and Shi, August and Choudhary, Rutvik and Zhang, Zhekun and Jain, Aryaman and Misailovic, Sasa. "Detecting flaky tests in probabilistic and machine learning applications." In *Proceedings of the 29th ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA)*, pp. 211-224. ACM, 2020. `PDF `__ Resources ^^^^^^^^^ From f55c66076374ecd9ce0bf0b42d8f96eebf2ca732 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 3 Apr 2024 12:18:24 +0000 Subject: [PATCH 6/9] [8.1.x] doc: `import pytest` in `conftest.py` example in `doctest.rst` (#12182) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Manuel López-Ibáñez <2620021+MLopez-Ibanez@users.noreply.github.com> --- doc/en/how-to/doctest.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/en/how-to/doctest.rst b/doc/en/how-to/doctest.rst index f70d28ce135..c2a6cc8e958 100644 --- a/doc/en/how-to/doctest.rst +++ b/doc/en/how-to/doctest.rst @@ -224,6 +224,7 @@ place the objects you want to appear in the doctest namespace: .. code-block:: python # content of conftest.py + import pytest import numpy From a43b09882d49a8ce9bcc872f4f70eb589a7a92ea Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:20:11 +0000 Subject: [PATCH 7/9] [8.1.x] Update events/trainings (#12237) Co-authored-by: Florian Bruhin --- doc/en/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/en/index.rst b/doc/en/index.rst index 08a1468986a..67501c0530c 100644 --- a/doc/en/index.rst +++ b/doc/en/index.rst @@ -5,7 +5,8 @@ - `Professional Testing with Python `_, via `Python Academy `_ (3 day in-depth training): * **June 11th to 13th 2024**, Remote * **March 4th to 6th 2025**, Leipzig, Germany / Remote - - `pytest development sprint `_, June 2024 (`date poll `_) + - `pytest development sprint `_, **June 17th -- 22nd 2024** + - pytest tips and tricks for a better testsuite, `Europython 2024 `_, **July 8th -- 14th 2024** (3h), Prague Also see :doc:`previous talks and blogposts `. From 0675383bac14ce8e8d04b94d8d08029ac26fbbfc Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:11:50 +0000 Subject: [PATCH 8/9] [8.1.x] Fixed Bug Regarding Attribute Error in pytest.approx For Types Implicitly Convertible to Numpy Arrays (#12240) --------- Co-authored-by: poulami-sau <109125687+poulami-sau@users.noreply.github.com> Co-authored-by: Bruno Oliveira --- AUTHORS | 1 + changelog/12114.bugfix.rst | 1 + src/_pytest/python_api.py | 14 +++++++++----- testing/python/approx.py | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) create mode 100644 changelog/12114.bugfix.rst diff --git a/AUTHORS b/AUTHORS index 4c4d68df147..92d3a14c7c5 100644 --- a/AUTHORS +++ b/AUTHORS @@ -318,6 +318,7 @@ Pierre Sassoulas Pieter Mulder Piotr Banaszkiewicz Piotr Helm +Poulami Sau Prakhar Gurunani Prashant Anand Prashant Sharma diff --git a/changelog/12114.bugfix.rst b/changelog/12114.bugfix.rst new file mode 100644 index 00000000000..220832da577 --- /dev/null +++ b/changelog/12114.bugfix.rst @@ -0,0 +1 @@ +Fixed error in :func:`pytest.approx` when used with `numpy` arrays and comparing with other types. diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 7e51da3194a..f6986a6a43e 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -142,7 +142,7 @@ def __repr__(self) -> str: ) return f"approx({list_scalars!r})" - def _repr_compare(self, other_side: "ndarray") -> List[str]: + def _repr_compare(self, other_side: Union["ndarray", List[Any]]) -> List[str]: import itertools import math @@ -163,10 +163,14 @@ def get_value_from_nested_list( self._approx_scalar, self.expected.tolist() ) - if np_array_shape != other_side.shape: + # Convert other_side to numpy array to ensure shape attribute is available. + other_side_as_array = _as_numpy_array(other_side) + assert other_side_as_array is not None + + if np_array_shape != other_side_as_array.shape: return [ "Impossible to compare arrays with different shapes.", - f"Shapes: {np_array_shape} and {other_side.shape}", + f"Shapes: {np_array_shape} and {other_side_as_array.shape}", ] number_of_elements = self.expected.size @@ -175,7 +179,7 @@ def get_value_from_nested_list( different_ids = [] for index in itertools.product(*(range(i) for i in np_array_shape)): approx_value = get_value_from_nested_list(approx_side_as_seq, index) - other_value = get_value_from_nested_list(other_side, index) + other_value = get_value_from_nested_list(other_side_as_array, index) if approx_value != other_value: abs_diff = abs(approx_value.expected - other_value) max_abs_diff = max(max_abs_diff, abs_diff) @@ -188,7 +192,7 @@ def get_value_from_nested_list( message_data = [ ( str(index), - str(get_value_from_nested_list(other_side, index)), + str(get_value_from_nested_list(other_side_as_array, index)), str(get_value_from_nested_list(approx_side_as_seq, index)), ) for index in different_ids diff --git a/testing/python/approx.py b/testing/python/approx.py index 079667bd093..cf8cc8d0375 100644 --- a/testing/python/approx.py +++ b/testing/python/approx.py @@ -763,6 +763,24 @@ def test_numpy_array_wrong_shape(self): assert a12 != approx(a21) assert a21 != approx(a12) + def test_numpy_array_implicit_conversion(self) -> None: + """#12114.""" + np = pytest.importorskip("numpy") + + class ImplicitArray: + """Type which is implicitly convertible to a numpy array.""" + + def __init__(self, vals): + self.vals = vals + + def __array__(self, dtype=None, copy=None): + return np.array(self.vals) + + vec1 = ImplicitArray([1.0, 2.0, 3.0]) + vec2 = ImplicitArray([1.0, 2.0, 4.0]) + # see issue #12114 for test case + assert vec1 != approx(vec2) + def test_numpy_array_protocol(self): """ array-like objects such as tensorflow's DeviceArray are handled like ndarray. From cf84163ac3549e657eed5ef2a4f4c7a5d1ffbe8c Mon Sep 17 00:00:00 2001 From: pytest bot Date: Fri, 26 Apr 2024 11:54:49 +0000 Subject: [PATCH 9/9] Prepare release version 8.1.2 --- changelog/12114.bugfix.rst | 1 - doc/en/announce/index.rst | 1 + doc/en/announce/release-8.1.2.rst | 18 ++++++++++++++++++ doc/en/changelog.rst | 9 +++++++++ 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 +- 8 files changed, 35 insertions(+), 8 deletions(-) delete mode 100644 changelog/12114.bugfix.rst create mode 100644 doc/en/announce/release-8.1.2.rst diff --git a/changelog/12114.bugfix.rst b/changelog/12114.bugfix.rst deleted file mode 100644 index 220832da577..00000000000 --- a/changelog/12114.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fixed error in :func:`pytest.approx` when used with `numpy` arrays and comparing with other types. diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst index 40eccdd748a..bb39eb7e6a1 100644 --- a/doc/en/announce/index.rst +++ b/doc/en/announce/index.rst @@ -6,6 +6,7 @@ Release announcements :maxdepth: 2 + release-8.1.2 release-8.1.1 release-8.1.0 release-8.0.2 diff --git a/doc/en/announce/release-8.1.2.rst b/doc/en/announce/release-8.1.2.rst new file mode 100644 index 00000000000..19e41e0f7c5 --- /dev/null +++ b/doc/en/announce/release-8.1.2.rst @@ -0,0 +1,18 @@ +pytest-8.1.2 +======================================= + +pytest 8.1.2 has just been released to PyPI. + +This is a bug-fix release, being a drop-in replacement. To upgrade:: + + pip install --upgrade pytest + +The full changelog is available at https://docs.pytest.org/en/stable/changelog.html. + +Thanks to all of the contributors to this release: + +* Bruno Oliveira + + +Happy testing, +The pytest Development Team diff --git a/doc/en/changelog.rst b/doc/en/changelog.rst index bea4257af0f..fb316e706ba 100644 --- a/doc/en/changelog.rst +++ b/doc/en/changelog.rst @@ -28,6 +28,15 @@ with advance notice in the **Deprecations** section of releases. .. towncrier release notes start +pytest 8.1.2 (2024-04-26) +========================= + +Bug Fixes +--------- + +- `#12114 `_: Fixed error in :func:`pytest.approx` when used with `numpy` arrays and comparing with other types. + + pytest 8.1.1 (2024-03-08) ========================= diff --git a/doc/en/example/parametrize.rst b/doc/en/example/parametrize.rst index ad17ce0b430..672c7c4457d 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 68737267ef4..c01e685f3f4 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 40632645d16..e96eabbc5e7 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.1 + pytest 8.1.2 .. _`simpletest`: diff --git a/doc/en/how-to/fixtures.rst b/doc/en/how-to/fixtures.rst index 795d2caf50d..ba416ccbc23 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 - +