From f8070ffb9b0a0f5618190d9311cf2a99e7b18a52 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 25 Oct 2023 13:37:56 +0000 Subject: [PATCH 01/12] [7.4.x] Add deploy instructions using the command-line (#11553) Co-authored-by: Bruno Oliveira --- scripts/prepare-release-pr.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/scripts/prepare-release-pr.py b/scripts/prepare-release-pr.py index a0e5e4d7f37..8ffa6696466 100644 --- a/scripts/prepare-release-pr.py +++ b/scripts/prepare-release-pr.py @@ -31,16 +31,22 @@ class InvalidFeatureRelease(Exception): SLUG = "pytest-dev/pytest" PR_BODY = """\ -Created by the [prepare release pr](https://github.com/pytest-dev/pytest/actions/workflows/prepare-release-pr.yml) -workflow. +Created by the [prepare release pr]\ +(https://github.com/pytest-dev/pytest/actions/workflows/prepare-release-pr.yml) workflow. -Once all builds pass and it has been **approved** by one or more maintainers, -start the [deploy](https://github.com/pytest-dev/pytest/actions/workflows/deploy.yml) workflow, using these parameters: +Once all builds pass and it has been **approved** by one or more maintainers, start the \ +[deploy](https://github.com/pytest-dev/pytest/actions/workflows/deploy.yml) workflow, using these parameters: * `Use workflow from`: `release-{version}`. * `Release version`: `{version}`. -After the `deploy` workflow has been approved by a core maintainer, the package will be uploaded to PyPI automatically. +Or execute on the command line: + +```console +gh workflow run deploy.yml -r release-{version} -f version={version} +``` + +After the workflow has been approved by a core maintainer, the package will be uploaded to PyPI automatically. """ From a32feda04c706e16411ac0a80a8adfcd575a35ff Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 25 Oct 2023 13:28:22 -0300 Subject: [PATCH 02/12] Fix tag name generated by deploy workflow (#11550) (#11554) Traditionally pytest publishes tags in the form `X.Y.Z`, however the deploy workflow (copied from somewhere else) published tags in the form `vX.Y.Z`. This is the root cause of #11548, because it tried to publish the release notes for tag `X.Y.Z` (which did not exist). Fix #11548 (cherry picked from commit c1728948ac7bcd807a40f9aaae63f2f09f5df5b7) --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 7340e13664c..09c14e405b1 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -53,8 +53,8 @@ jobs: run: | git config user.name "pytest bot" git config user.email "pytestbot@gmail.com" - git tag --annotate --message=v${{ github.event.inputs.version }} v${{ github.event.inputs.version }} ${{ github.sha }} - git push origin v${{ github.event.inputs.version }} + git tag --annotate --message=v${{ github.event.inputs.version }} ${{ github.event.inputs.version }} ${{ github.sha }} + git push origin ${{ github.event.inputs.version }} release-notes: From ec5bd27cc759228cb57ece3cb549b527ee98dc99 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Fri, 27 Oct 2023 10:36:51 -0300 Subject: [PATCH 03/12] Update build-and-inspect-python-package action (#11561) (#11562) This should fix the action for Python 3.12. Ref: hynek/build-and-inspect-python-package#72 (cherry picked from commit 247436819a49a4c21c0926ed0a12bfe7e8166237) --- .github/workflows/deploy.yml | 2 +- .github/workflows/test.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 09c14e405b1..9243007b697 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -26,7 +26,7 @@ jobs: persist-credentials: false - name: Build and Check Package - uses: hynek/build-and-inspect-python-package@v1.5 + uses: hynek/build-and-inspect-python-package@v1.5.3 deploy: if: github.repository == 'pytest-dev/pytest' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index a3c2d9ed5a1..de0bfea5234 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -35,7 +35,7 @@ jobs: fetch-depth: 0 persist-credentials: false - name: Build and Check Package - uses: hynek/build-and-inspect-python-package@v1.5 + uses: hynek/build-and-inspect-python-package@v1.5.3 build: needs: [package] From bd068705b1f4ba0db07079feabb869cb2815df7a Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Mon, 30 Oct 2023 09:01:54 +0200 Subject: [PATCH 04/12] [7.4.x] doc/reference: fix sidebar TOC depth --- doc/en/reference/reference.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index 6e11d385d12..ff61e3b49d0 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -1,3 +1,5 @@ +:tocdepth: 3 + .. _`api-reference`: API Reference From a40dacf6577ae990740e10572582538dfaf357b6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 14 Nov 2023 15:08:28 +0000 Subject: [PATCH 05/12] [7.4.x] XFAIL TestLocalPath.test_make_numbered_dir_multiprocess_safe (#11616) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Miro HronĨok --- testing/_py/test_local.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/testing/_py/test_local.py b/testing/_py/test_local.py index 348682b5396..fc20bd63b86 100644 --- a/testing/_py/test_local.py +++ b/testing/_py/test_local.py @@ -868,6 +868,9 @@ def test_fspath_protocol_other_class(self, fake_fspath_obj): py_path.strpath, str_path ) + @pytest.mark.xfail( + reason="#11603", raises=(error.EEXIST, error.ENOENT), strict=False + ) def test_make_numbered_dir_multiprocess_safe(self, tmpdir): # https://github.com/pytest-dev/py/issues/30 with multiprocessing.Pool() as pool: From 13024efd7afdbae80ce70d27295d9bbe62670cb8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 22 Nov 2023 20:25:29 +0000 Subject: [PATCH 06/12] [7.4.x] Fix for operation on closed file in faulthandler teardown (#11631) Co-authored-by: Simon Blanchard --- changelog/11572.bugfix.rst | 1 + src/_pytest/faulthandler.py | 20 ++++++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 changelog/11572.bugfix.rst diff --git a/changelog/11572.bugfix.rst b/changelog/11572.bugfix.rst new file mode 100644 index 00000000000..7a235a071fe --- /dev/null +++ b/changelog/11572.bugfix.rst @@ -0,0 +1 @@ +Handle an edge case where :data:`sys.stderr` and :data:`sys.__stderr__` might already be closed when :ref:`faulthandler` is tearing down. diff --git a/src/_pytest/faulthandler.py b/src/_pytest/faulthandler.py index 36040bffffc..d8c7e9fd3b6 100644 --- a/src/_pytest/faulthandler.py +++ b/src/_pytest/faulthandler.py @@ -9,8 +9,8 @@ from _pytest.stash import StashKey +fault_handler_original_stderr_fd_key = StashKey[int]() fault_handler_stderr_fd_key = StashKey[int]() -fault_handler_originally_enabled_key = StashKey[bool]() def pytest_addoption(parser: Parser) -> None: @@ -24,8 +24,15 @@ def pytest_addoption(parser: Parser) -> None: def pytest_configure(config: Config) -> None: import faulthandler - config.stash[fault_handler_stderr_fd_key] = os.dup(get_stderr_fileno()) - config.stash[fault_handler_originally_enabled_key] = faulthandler.is_enabled() + # at teardown we want to restore the original faulthandler fileno + # but faulthandler has no api to return the original fileno + # so here we stash the stderr fileno to be used at teardown + # sys.stderr and sys.__stderr__ may be closed or patched during the session + # so we can't rely on their values being good at that point (#11572). + stderr_fileno = get_stderr_fileno() + if faulthandler.is_enabled(): + config.stash[fault_handler_original_stderr_fd_key] = stderr_fileno + config.stash[fault_handler_stderr_fd_key] = os.dup(stderr_fileno) faulthandler.enable(file=config.stash[fault_handler_stderr_fd_key]) @@ -37,9 +44,10 @@ def pytest_unconfigure(config: Config) -> None: if fault_handler_stderr_fd_key in config.stash: os.close(config.stash[fault_handler_stderr_fd_key]) del config.stash[fault_handler_stderr_fd_key] - if config.stash.get(fault_handler_originally_enabled_key, False): - # Re-enable the faulthandler if it was originally enabled. - faulthandler.enable(file=get_stderr_fileno()) + # Re-enable the faulthandler if it was originally enabled. + if fault_handler_original_stderr_fd_key in config.stash: + faulthandler.enable(config.stash[fault_handler_original_stderr_fd_key]) + del config.stash[fault_handler_original_stderr_fd_key] def get_stderr_fileno() -> int: From 5582bfcddf78929f7979c5023b167b333e1c2dd9 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 14 Dec 2023 08:19:40 -0300 Subject: [PATCH 07/12] [7.4.x] Improves clarity in Sphinx documentation for function signature. (#11702) Co-authored-by: Arthur Richard --- AUTHORS | 1 + doc/en/reference/reference.rst | 2 +- src/_pytest/outcomes.py | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/AUTHORS b/AUTHORS index be1e7863860..cb73916bcaa 100644 --- a/AUTHORS +++ b/AUTHORS @@ -47,6 +47,7 @@ Ariel Pillemer Armin Rigo Aron Coyle Aron Curzon +Arthur Richard Ashish Kurmi Aviral Verma Aviv Palivoda diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst index ff61e3b49d0..c80bdb18eb5 100644 --- a/doc/en/reference/reference.rst +++ b/doc/en/reference/reference.rst @@ -79,7 +79,7 @@ pytest.xfail pytest.exit ~~~~~~~~~~~ -.. autofunction:: pytest.exit(reason, [returncode=False, msg=None]) +.. autofunction:: pytest.exit(reason, [returncode=None, msg=None]) pytest.main ~~~~~~~~~~~ diff --git a/src/_pytest/outcomes.py b/src/_pytest/outcomes.py index 1be97dda4ea..53c3e1511cb 100644 --- a/src/_pytest/outcomes.py +++ b/src/_pytest/outcomes.py @@ -123,7 +123,7 @@ def exit( only because `msg` is deprecated. :param returncode: - Return code to be used when exiting pytest. + Return code to be used when exiting pytest. None means the same as ``0`` (no error), same as :func:`sys.exit`. :param msg: Same as ``reason``, but deprecated. Will be removed in a future version, use ``reason`` instead. From d06c05bd23ea6af8e07fd944e56c58b64375b724 Mon Sep 17 00:00:00 2001 From: Ran Benita Date: Sun, 31 Dec 2023 10:14:23 +0200 Subject: [PATCH 08/12] [7.4.x] nodes: fix tracebacks from collection errors are not getting pruned --- changelog/11710.bugfix.rst | 1 + src/_pytest/nodes.py | 2 +- testing/test_collection.py | 23 +++++++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 changelog/11710.bugfix.rst diff --git a/changelog/11710.bugfix.rst b/changelog/11710.bugfix.rst new file mode 100644 index 00000000000..4bbf9fa2e7d --- /dev/null +++ b/changelog/11710.bugfix.rst @@ -0,0 +1 @@ +Fixed tracebacks from collection errors not getting pruned. diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 667a02b77af..a5313cb7656 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -567,7 +567,7 @@ def _traceback_filter(self, excinfo: ExceptionInfo[BaseException]) -> Traceback: ntraceback = traceback.cut(path=self.path) if ntraceback == traceback: ntraceback = ntraceback.cut(excludepath=tracebackcutdir) - return excinfo.traceback.filter(excinfo) + return ntraceback.filter(excinfo) return excinfo.traceback diff --git a/testing/test_collection.py b/testing/test_collection.py index 8b0a1ab3650..5d4b0a75853 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -345,6 +345,29 @@ def pytest_make_collect_report(): result = pytester.runpytest(p) result.stdout.fnmatch_lines(["*ERROR collecting*", "*header1*"]) + def test_collection_error_traceback_is_clean(self, pytester: Pytester) -> None: + """When a collection error occurs, the report traceback doesn't contain + internal pytest stack entries. + + Issue #11710. + """ + pytester.makepyfile( + """ + raise Exception("LOUSY") + """ + ) + result = pytester.runpytest() + result.stdout.fnmatch_lines( + [ + "*ERROR collecting*", + "test_*.py:1: in ", + ' raise Exception("LOUSY")', + "E Exception: LOUSY", + "*= short test summary info =*", + ], + consecutive=True, + ) + class TestCustomConftests: def test_ignore_collect_path(self, pytester: Pytester) -> None: From b1f3387d42571090ee4a35ec1945765b7f2ffae8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 31 Dec 2023 11:50:38 +0200 Subject: [PATCH 09/12] [7.4.x] #11091: documentation should use hypthonated properties (#11750) --- AUTHORS | 1 + changelog/11091.doc.rst | 1 + changelog/README.rst | 2 +- doc/en/deprecations.rst | 2 +- doc/en/example/markers.rst | 2 +- doc/en/example/simple.rst | 2 +- doc/en/how-to/output.rst | 2 +- src/_pytest/junitxml.py | 2 +- src/_pytest/pytester.py | 2 +- testing/python/metafunc.py | 2 +- 10 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 changelog/11091.doc.rst diff --git a/AUTHORS b/AUTHORS index cb73916bcaa..f633ef9e995 100644 --- a/AUTHORS +++ b/AUTHORS @@ -324,6 +324,7 @@ Ronny Pfannschmidt Ross Lawley Ruaridh Williamson Russel Winder +Ryan Puddephatt Ryan Wooden Saiprasad Kale Samuel Colvin diff --git a/changelog/11091.doc.rst b/changelog/11091.doc.rst new file mode 100644 index 00000000000..b5e2af36061 --- /dev/null +++ b/changelog/11091.doc.rst @@ -0,0 +1 @@ +Updated documentation to refer to hyphenated options: replaced ``--junitxml`` with ``--junit-xml`` and ``--collectonly`` with ``--collect-only``. diff --git a/changelog/README.rst b/changelog/README.rst index 6d026f57ef3..88956ef28d8 100644 --- a/changelog/README.rst +++ b/changelog/README.rst @@ -14,7 +14,7 @@ Each file should be named like ``..rst``, where ```` is an issue number, and ```` is one of: * ``feature``: new user facing features, like new command-line options and new behavior. -* ``improvement``: improvement of existing functionality, usually without requiring user intervention (for example, new fields being written in ``--junitxml``, improved colors in terminal, etc). +* ``improvement``: improvement of existing functionality, usually without requiring user intervention (for example, new fields being written in ``--junit-xml``, improved colors in terminal, etc). * ``bugfix``: fixes a bug. * ``doc``: documentation improvement, like rewording an entire session or adding missing docs. * ``deprecation``: feature deprecation. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 4f7830a2791..3bb93d81ef6 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -596,7 +596,7 @@ By using ``legacy`` you will keep using the legacy/xunit1 format when upgrading pytest 6.0, where the default format will be ``xunit2``. In order to let users know about the transition, pytest will issue a warning in case -the ``--junitxml`` option is given in the command line but ``junit_family`` is not explicitly +the ``--junit-xml`` option is given in the command line but ``junit_family`` is not explicitly configured in ``pytest.ini``. Services known to support the ``xunit2`` format: diff --git a/doc/en/example/markers.rst b/doc/en/example/markers.rst index 55fd1f576cf..6cdf4eb42d8 100644 --- a/doc/en/example/markers.rst +++ b/doc/en/example/markers.rst @@ -136,7 +136,7 @@ Or select multiple nodes: Node IDs for failing tests are displayed in the test summary info when running pytest with the ``-rf`` option. You can also - construct Node IDs from the output of ``pytest --collectonly``. + construct Node IDs from the output of ``pytest --collect-only``. Using ``-k expr`` to select tests based on their name ------------------------------------------------------- diff --git a/doc/en/example/simple.rst b/doc/en/example/simple.rst index 32e5188b741..ba2920daf6f 100644 --- a/doc/en/example/simple.rst +++ b/doc/en/example/simple.rst @@ -1088,4 +1088,4 @@ application with standard ``pytest`` command-line options: .. code-block:: bash - ./app_main --pytest --verbose --tb=long --junitxml=results.xml test-suite/ + ./app_main --pytest --verbose --tb=long --junit=xml=results.xml test-suite/ diff --git a/doc/en/how-to/output.rst b/doc/en/how-to/output.rst index e8e9af0c70b..cf72a2d291c 100644 --- a/doc/en/how-to/output.rst +++ b/doc/en/how-to/output.rst @@ -478,7 +478,7 @@ integration servers, use this invocation: .. code-block:: bash - pytest --junitxml=path + pytest --junit-xml=path to create an XML file at ``path``. diff --git a/src/_pytest/junitxml.py b/src/_pytest/junitxml.py index ed259e4c41d..9ee35b84e84 100644 --- a/src/_pytest/junitxml.py +++ b/src/_pytest/junitxml.py @@ -369,7 +369,7 @@ def test_foo(record_testsuite_property): __tracebackhide__ = True def record_func(name: str, value: object) -> None: - """No-op function in case --junitxml was not passed in the command-line.""" + """No-op function in case --junit-xml was not passed in the command-line.""" __tracebackhide__ = True _check_record_param_type("name", name) diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py index cdfc2c04ae1..0771065e065 100644 --- a/src/_pytest/pytester.py +++ b/src/_pytest/pytester.py @@ -1074,7 +1074,7 @@ def inline_runsource(self, source: str, *cmdlineargs) -> HookRecorder: return self.inline_run(*values) def inline_genitems(self, *args) -> Tuple[List[Item], HookRecorder]: - """Run ``pytest.main(['--collectonly'])`` in-process. + """Run ``pytest.main(['--collect-only'])`` in-process. Runs the :py:func:`pytest.main` function to run all of pytest inside the test process itself like :py:meth:`inline_run`, but returns a diff --git a/testing/python/metafunc.py b/testing/python/metafunc.py index a9e9b526934..dfb2dffb55e 100644 --- a/testing/python/metafunc.py +++ b/testing/python/metafunc.py @@ -1493,7 +1493,7 @@ def test_foo(x): pass """ ) - result = pytester.runpytest("--collectonly") + result = pytester.runpytest("--collect-only") result.stdout.fnmatch_lines( [ "collected 0 items / 1 error", From a0f58fa9e7f9b09b212ed491464be5df9b80fc0b Mon Sep 17 00:00:00 2001 From: Zac Hatfield-Dodds Date: Tue, 4 Jul 2023 10:47:13 -0700 Subject: [PATCH 10/12] Merge pull request #11143 from tushar-deepsource/patch-1 (cherry picked from commit 084d756ae6a03bba7a257ebae3c83095b228988f) [ran: adapted to 7.4.x, fixed changelog issue number] --- AUTHORS | 1 + changelog/11140.bugfix.rst | 1 + src/_pytest/assertion/rewrite.py | 14 ++++++++++---- testing/test_assertrewrite.py | 14 ++++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 changelog/11140.bugfix.rst diff --git a/AUTHORS b/AUTHORS index cb73916bcaa..1eeb3869adf 100644 --- a/AUTHORS +++ b/AUTHORS @@ -376,6 +376,7 @@ Tomer Keren Tony Narlock Tor Colvin Trevor Bekolay +Tushar Sadhwani Tyler Goodlet Tyler Smart Tzu-ping Chung diff --git a/changelog/11140.bugfix.rst b/changelog/11140.bugfix.rst new file mode 100644 index 00000000000..cdf0b37c7bf --- /dev/null +++ b/changelog/11140.bugfix.rst @@ -0,0 +1 @@ +Fix non-string constants at the top of file being detected as docstrings on Python>=3.8. diff --git a/src/_pytest/assertion/rewrite.py b/src/_pytest/assertion/rewrite.py index fd23552973e..d1974bb3b4a 100644 --- a/src/_pytest/assertion/rewrite.py +++ b/src/_pytest/assertion/rewrite.py @@ -604,6 +604,13 @@ def _write_and_reset() -> None: return ret +def _get_ast_constant_value(value: astStr) -> object: + if sys.version_info >= (3, 8): + return value.value + else: + return value.s + + class AssertionRewriter(ast.NodeVisitor): """Assertion rewriting implementation. @@ -700,11 +707,10 @@ def run(self, mod: ast.Module) -> None: expect_docstring and isinstance(item, ast.Expr) and isinstance(item.value, astStr) + and isinstance(_get_ast_constant_value(item.value), str) ): - if sys.version_info >= (3, 8): - doc = item.value.value - else: - doc = item.value.s + doc = _get_ast_constant_value(item.value) + assert isinstance(doc, str) if self.is_rewrite_disabled(doc): return expect_docstring = False diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index fbf2854953f..2f59ace54fc 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -2077,3 +2077,17 @@ def test_max_increased_verbosity(self, pytester: Pytester) -> None: self.create_test_file(pytester, DEFAULT_REPR_MAX_SIZE * 10) result = pytester.runpytest("-vv") result.stdout.no_fnmatch_line("*xxx...xxx*") + + +class TestIssue11140: + def test_constant_not_picked_as_module_docstring(self, pytester: Pytester) -> None: + pytester.makepyfile( + """\ + 0 + + def test_foo(): + pass + """ + ) + result = pytester.runpytest() + assert result.ret == 0 From 531d76daa4a871df5b2a46cae132851c29abf027 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 31 Dec 2023 12:11:02 +0200 Subject: [PATCH 11/12] [7.4.x] Improve reporting from __iter__ exceptions (#11749) --- changelog/7966.bugfix.rst | 1 + src/_pytest/assertion/util.py | 2 +- testing/test_assertrewrite.py | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 changelog/7966.bugfix.rst diff --git a/changelog/7966.bugfix.rst b/changelog/7966.bugfix.rst new file mode 100644 index 00000000000..849bdb06e97 --- /dev/null +++ b/changelog/7966.bugfix.rst @@ -0,0 +1 @@ +Removed unhelpful error message from assertion rewrite mechanism when exceptions are raised in ``__iter__`` methods. Now they are treated un-iterable instead. diff --git a/src/_pytest/assertion/util.py b/src/_pytest/assertion/util.py index fc5dfdbd5ba..39ca5403e04 100644 --- a/src/_pytest/assertion/util.py +++ b/src/_pytest/assertion/util.py @@ -132,7 +132,7 @@ def isiterable(obj: Any) -> bool: try: iter(obj) return not istext(obj) - except TypeError: + except Exception: return False diff --git a/testing/test_assertrewrite.py b/testing/test_assertrewrite.py index fbf2854953f..f64d7733cdc 100644 --- a/testing/test_assertrewrite.py +++ b/testing/test_assertrewrite.py @@ -686,6 +686,25 @@ def myany(x) -> bool: assert msg is not None assert " < 0" in msg + def test_assert_handling_raise_in__iter__(self, pytester: Pytester) -> None: + pytester.makepyfile( + """\ + class A: + def __iter__(self): + raise ValueError() + + def __eq__(self, o: object) -> bool: + return self is o + + def __repr__(self): + return "" + + assert A() == A() + """ + ) + result = pytester.runpytest() + result.stdout.fnmatch_lines(["*E*assert == "]) + def test_formatchar(self) -> None: def f() -> None: assert "%test" == "test" # type: ignore[comparison-overlap] From 33f694f4b30c5c502f21f81cb8ab907b12ad2f65 Mon Sep 17 00:00:00 2001 From: pytest bot Date: Sun, 31 Dec 2023 10:17:27 +0000 Subject: [PATCH 12/12] Prepare release version 7.4.4 --- changelog/11091.doc.rst | 1 - changelog/11140.bugfix.rst | 1 - changelog/11572.bugfix.rst | 1 - changelog/11710.bugfix.rst | 1 - changelog/7966.bugfix.rst | 1 - doc/en/announce/index.rst | 1 + doc/en/announce/release-7.4.4.rst | 20 ++++++++++++++++++++ doc/en/changelog.rst | 25 +++++++++++++++++++++++++ doc/en/getting-started.rst | 2 +- 9 files changed, 47 insertions(+), 6 deletions(-) delete mode 100644 changelog/11091.doc.rst delete mode 100644 changelog/11140.bugfix.rst delete mode 100644 changelog/11572.bugfix.rst delete mode 100644 changelog/11710.bugfix.rst delete mode 100644 changelog/7966.bugfix.rst create mode 100644 doc/en/announce/release-7.4.4.rst diff --git a/changelog/11091.doc.rst b/changelog/11091.doc.rst deleted file mode 100644 index b5e2af36061..00000000000 --- a/changelog/11091.doc.rst +++ /dev/null @@ -1 +0,0 @@ -Updated documentation to refer to hyphenated options: replaced ``--junitxml`` with ``--junit-xml`` and ``--collectonly`` with ``--collect-only``. diff --git a/changelog/11140.bugfix.rst b/changelog/11140.bugfix.rst deleted file mode 100644 index cdf0b37c7bf..00000000000 --- a/changelog/11140.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fix non-string constants at the top of file being detected as docstrings on Python>=3.8. diff --git a/changelog/11572.bugfix.rst b/changelog/11572.bugfix.rst deleted file mode 100644 index 7a235a071fe..00000000000 --- a/changelog/11572.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Handle an edge case where :data:`sys.stderr` and :data:`sys.__stderr__` might already be closed when :ref:`faulthandler` is tearing down. diff --git a/changelog/11710.bugfix.rst b/changelog/11710.bugfix.rst deleted file mode 100644 index 4bbf9fa2e7d..00000000000 --- a/changelog/11710.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Fixed tracebacks from collection errors not getting pruned. diff --git a/changelog/7966.bugfix.rst b/changelog/7966.bugfix.rst deleted file mode 100644 index 849bdb06e97..00000000000 --- a/changelog/7966.bugfix.rst +++ /dev/null @@ -1 +0,0 @@ -Removed unhelpful error message from assertion rewrite mechanism when exceptions are raised in ``__iter__`` methods. Now they are treated un-iterable instead. diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst index 854666f6725..35fd2c814e2 100644 --- a/doc/en/announce/index.rst +++ b/doc/en/announce/index.rst @@ -6,6 +6,7 @@ Release announcements :maxdepth: 2 + release-7.4.4 release-7.4.3 release-7.4.2 release-7.4.1 diff --git a/doc/en/announce/release-7.4.4.rst b/doc/en/announce/release-7.4.4.rst new file mode 100644 index 00000000000..c9633678d2e --- /dev/null +++ b/doc/en/announce/release-7.4.4.rst @@ -0,0 +1,20 @@ +pytest-7.4.4 +======================================= + +pytest 7.4.4 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 +* Ran Benita +* Zac Hatfield-Dodds + + +Happy testing, +The pytest Development Team diff --git a/doc/en/changelog.rst b/doc/en/changelog.rst index 121d1708da7..6973a08c9c6 100644 --- a/doc/en/changelog.rst +++ b/doc/en/changelog.rst @@ -28,6 +28,31 @@ with advance notice in the **Deprecations** section of releases. .. towncrier release notes start +pytest 7.4.4 (2023-12-31) +========================= + +Bug Fixes +--------- + +- `#11140 `_: Fix non-string constants at the top of file being detected as docstrings on Python>=3.8. + + +- `#11572 `_: Handle an edge case where :data:`sys.stderr` and :data:`sys.__stderr__` might already be closed when :ref:`faulthandler` is tearing down. + + +- `#11710 `_: Fixed tracebacks from collection errors not getting pruned. + + +- `#7966 `_: Removed unhelpful error message from assertion rewrite mechanism when exceptions are raised in ``__iter__`` methods. Now they are treated un-iterable instead. + + + +Improved Documentation +---------------------- + +- `#11091 `_: Updated documentation to refer to hyphenated options: replaced ``--junitxml`` with ``--junit-xml`` and ``--collectonly`` with ``--collect-only``. + + pytest 7.4.3 (2023-10-24) ========================= diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst index ba6facd4cd9..cd9ef9a66d3 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 7.4.3 + pytest 7.4.4 .. _`simpletest`: