From b6c55787fec3a3584ee7f73ada9568708f7c004c Mon Sep 17 00:00:00 2001
From: Bruno Oliveira <nicoddemus@gmail.com>
Date: Mon, 3 Jul 2023 13:17:02 -0300
Subject: [PATCH 01/27] Switch to deploy environment and configure for pypi
 oidc (#10925) (#11162)

Closes #10871
Closes #10870

Co-authored-by: Ronny Pfannschmidt <opensource@ronnypfannschmidt.de>
---
 .github/workflows/deploy.yml | 40 ++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 25280994687..e6b4f0ea2d7 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -13,40 +13,54 @@ on:
 permissions: {}
 
 jobs:
-
-  deploy:
-    if: github.repository == 'pytest-dev/pytest'
-
+  build:
     runs-on: ubuntu-latest
-    timeout-minutes: 30
-    permissions:
-      contents: write
-
+    timeout-minutes: 10
     steps:
     - uses: actions/checkout@v3
       with:
         fetch-depth: 0
         persist-credentials: false
-
     - name: Build and Check Package
       uses: hynek/build-and-inspect-python-package@v1.5
 
+  deploy:
+    if: github.repository == 'pytest-dev/pytest'
+    needs: [build]
+    runs-on: ubuntu-latest
+    timeout-minutes: 30
+    permissions:
+      id-token: write
+    steps:
     - name: Download Package
       uses: actions/download-artifact@v3
       with:
         name: Packages
         path: dist
-
     - name: Publish package to PyPI
-      uses: pypa/gh-action-pypi-publish@release/v1
-      with:
-        password: ${{ secrets.pypi_token }}
+      uses: pypa/gh-action-pypi-publish@v1.8.5
+
+  release-notes:
 
+    # todo: generate the content in the build  job
+    #       the goal being of using a github action script to push the release data
+    #       after success instead of creating a complete python/tox env
+    needs: [deploy]
+    runs-on: ubuntu-latest
+    timeout-minutes: 30
+    permissions:
+      contents: write
+    steps:
+    - uses: actions/checkout@v3
+      with:
+        fetch-depth: 0
+        persist-credentials: false
     - name: Set up Python
       uses: actions/setup-python@v4
       with:
         python-version: "3.7"
 
+
     - name: Install tox
       run: |
         python -m pip install --upgrade pip

From a4d7254d18a201016b97ce6a6e3f41a124e7e84c Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Mon, 3 Jul 2023 16:33:47 +0000
Subject: [PATCH 02/27] [7.4.x] Fix duplicated imports with importlib mode and
 doctest-modules (#11164)

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
---
 changelog/10811.bugfix.rst |  2 ++
 src/_pytest/pathlib.py     |  2 ++
 testing/acceptance_test.py | 35 +++++++++++++++++++++++++++++++++++
 testing/test_pathlib.py    | 27 +++++++++++++++++++--------
 4 files changed, 58 insertions(+), 8 deletions(-)
 create mode 100644 changelog/10811.bugfix.rst

diff --git a/changelog/10811.bugfix.rst b/changelog/10811.bugfix.rst
new file mode 100644
index 00000000000..aa26414e457
--- /dev/null
+++ b/changelog/10811.bugfix.rst
@@ -0,0 +1,2 @@
+Fixed issue when using ``--import-mode=importlib`` together with ``--doctest-modules`` that caused modules
+to be imported more than once, causing problems with modules that have import side effects.
diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py
index 70383e4b504..e5fdd639a82 100644
--- a/src/_pytest/pathlib.py
+++ b/src/_pytest/pathlib.py
@@ -523,6 +523,8 @@ def import_path(
 
     if mode is ImportMode.importlib:
         module_name = module_name_from_path(path, root)
+        with contextlib.suppress(KeyError):
+            return sys.modules[module_name]
 
         for meta_importer in sys.meta_path:
             spec = meta_importer.find_spec(module_name, [str(path.parent)])
diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py
index 5658f2fd6b8..ed750a97071 100644
--- a/testing/acceptance_test.py
+++ b/testing/acceptance_test.py
@@ -1317,3 +1317,38 @@ def test_stuff():
     )
     res = pytester.runpytest()
     res.stdout.fnmatch_lines(["*Did you mean to use `assert` instead of `return`?*"])
+
+
+def test_doctest_and_normal_imports_with_importlib(pytester: Pytester) -> None:
+    """
+    Regression test for #10811: previously import_path with ImportMode.importlib would
+    not return a module if already in sys.modules, resulting in modules being imported
+    multiple times, which causes problems with modules that have import side effects.
+    """
+    # Uses the exact reproducer form #10811, given it is very minimal
+    # and illustrates the problem well.
+    pytester.makepyfile(
+        **{
+            "pmxbot/commands.py": "from . import logging",
+            "pmxbot/logging.py": "",
+            "tests/__init__.py": "",
+            "tests/test_commands.py": """
+                import importlib
+                from pmxbot import logging
+
+                class TestCommands:
+                    def test_boo(self):
+                        assert importlib.import_module('pmxbot.logging') is logging
+                """,
+        }
+    )
+    pytester.makeini(
+        """
+        [pytest]
+        addopts=
+            --doctest-modules
+            --import-mode importlib
+        """
+    )
+    result = pytester.runpytest_subprocess()
+    result.stdout.fnmatch_lines("*1 passed*")
diff --git a/testing/test_pathlib.py b/testing/test_pathlib.py
index 56c54e484da..945d6f7d746 100644
--- a/testing/test_pathlib.py
+++ b/testing/test_pathlib.py
@@ -7,6 +7,7 @@
 from types import ModuleType
 from typing import Any
 from typing import Generator
+from typing import Iterator
 
 import pytest
 from _pytest.monkeypatch import MonkeyPatch
@@ -282,29 +283,36 @@ def test_invalid_path(self, tmp_path: Path) -> None:
             import_path(tmp_path / "invalid.py", root=tmp_path)
 
     @pytest.fixture
-    def simple_module(self, tmp_path: Path) -> Path:
-        fn = tmp_path / "_src/tests/mymod.py"
+    def simple_module(
+        self, tmp_path: Path, request: pytest.FixtureRequest
+    ) -> Iterator[Path]:
+        name = f"mymod_{request.node.name}"
+        fn = tmp_path / f"_src/tests/{name}.py"
         fn.parent.mkdir(parents=True)
         fn.write_text("def foo(x): return 40 + x", encoding="utf-8")
-        return fn
+        module_name = module_name_from_path(fn, root=tmp_path)
+        yield fn
+        sys.modules.pop(module_name, None)
 
-    def test_importmode_importlib(self, simple_module: Path, tmp_path: Path) -> None:
+    def test_importmode_importlib(
+        self, simple_module: Path, tmp_path: Path, request: pytest.FixtureRequest
+    ) -> None:
         """`importlib` mode does not change sys.path."""
         module = import_path(simple_module, mode="importlib", root=tmp_path)
         assert module.foo(2) == 42  # type: ignore[attr-defined]
         assert str(simple_module.parent) not in sys.path
         assert module.__name__ in sys.modules
-        assert module.__name__ == "_src.tests.mymod"
+        assert module.__name__ == f"_src.tests.mymod_{request.node.name}"
         assert "_src" in sys.modules
         assert "_src.tests" in sys.modules
 
-    def test_importmode_twice_is_different_module(
+    def test_remembers_previous_imports(
         self, simple_module: Path, tmp_path: Path
     ) -> None:
-        """`importlib` mode always returns a new module."""
+        """`importlib` mode called remembers previous module (#10341, #10811)."""
         module1 = import_path(simple_module, mode="importlib", root=tmp_path)
         module2 = import_path(simple_module, mode="importlib", root=tmp_path)
-        assert module1 is not module2
+        assert module1 is module2
 
     def test_no_meta_path_found(
         self, simple_module: Path, monkeypatch: MonkeyPatch, tmp_path: Path
@@ -317,6 +325,9 @@ def test_no_meta_path_found(
         # mode='importlib' fails if no spec is found to load the module
         import importlib.util
 
+        # Force module to be re-imported.
+        del sys.modules[module.__name__]
+
         monkeypatch.setattr(
             importlib.util, "spec_from_file_location", lambda *args: None
         )

From d53951836dc2ef6cbc454356243460640737c49b Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Tue, 4 Jul 2023 21:49:24 +0000
Subject: [PATCH 03/27] [7.4.x] Update open trainings (#11172)

Co-authored-by: Florian Bruhin <me@the-compiler.org>
---
 doc/en/index.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/doc/en/index.rst b/doc/en/index.rst
index de07831ac14..50f3e9c10c3 100644
--- a/doc/en/index.rst
+++ b/doc/en/index.rst
@@ -2,8 +2,9 @@
 
 .. sidebar:: Next Open Trainings
 
-   - `pytest tips and tricks for a better testsuite <https://ep2023.europython.eu/session/pytest-tips-and-tricks-for-a-better-testsuite>`_, at `Europython 2023 <https://ep2023.europython.eu/>`_, July 18th (3h), Prague/Remote
-   - `Professional Testing with Python <https://python-academy.com/courses/python_course_testing.html>`_, via `Python Academy <https://www.python-academy.com/>`_, March 5th to 7th 2024 (3 day in-depth training), Leipzig/Remote
+   - `pytest tips and tricks for a better testsuite <https://ep2023.europython.eu/session/pytest-tips-and-tricks-for-a-better-testsuite>`_, at `Europython 2023 <https://ep2023.europython.eu/>`_, **July 18th** (3h), **Prague, Czech Republic / Remote**
+   - `pytest: Professionelles Testen (nicht nur) für Python <https://workshoptage.ch/workshops/2023/pytest-professionelles-testen-nicht-nur-fuer-python-2/>`_, at `Workshoptage 2023 <https://workshoptage.ch/>`_, **September 5th**, `OST <https://www.ost.ch/en>`_ Campus **Rapperswil, Switzerland**
+   - `Professional Testing with Python <https://python-academy.com/courses/python_course_testing.html>`_, via `Python Academy <https://www.python-academy.com/>`_, **March 5th to 7th 2024** (3 day in-depth training), **Leipzig, Germany / Remote**
 
    Also see :doc:`previous talks and blogposts <talks>`.
 

From c71b5df7347a84ef270888c8b93f5c8853ff76f0 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Sat, 8 Jul 2023 15:11:26 -0300
Subject: [PATCH 04/27] [7.4.x] Add child modules as attributes of parent
 modules. (#11163)

* [7.4.x] Add child modules as attributes of parent modules.

* Update 10337.bugfix.rst

---------

Co-authored-by: akhilramkee <31619526+akhilramkee@users.noreply.github.com>
Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
---
 changelog/10337.bugfix.rst |  2 ++
 src/_pytest/pathlib.py     | 14 +++++++++++++-
 testing/test_pathlib.py    | 12 ++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)
 create mode 100644 changelog/10337.bugfix.rst

diff --git a/changelog/10337.bugfix.rst b/changelog/10337.bugfix.rst
new file mode 100644
index 00000000000..3270016f926
--- /dev/null
+++ b/changelog/10337.bugfix.rst
@@ -0,0 +1,2 @@
+Fixed bug where fake intermediate modules generated by ``--import-mode=importlib`` would not include the
+child modules as attributes of the parent modules.
diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py
index e5fdd639a82..14fb2e3ae2f 100644
--- a/src/_pytest/pathlib.py
+++ b/src/_pytest/pathlib.py
@@ -635,6 +635,9 @@ def insert_missing_modules(modules: Dict[str, ModuleType], module_name: str) ->
     otherwise "src.tests.test_foo" is not importable by ``__import__``.
     """
     module_parts = module_name.split(".")
+    child_module: Union[ModuleType, None] = None
+    module: Union[ModuleType, None] = None
+    child_name: str = ""
     while module_name:
         if module_name not in modules:
             try:
@@ -644,13 +647,22 @@ def insert_missing_modules(modules: Dict[str, ModuleType], module_name: str) ->
                 # ourselves to fall back to creating a dummy module.
                 if not sys.meta_path:
                     raise ModuleNotFoundError
-                importlib.import_module(module_name)
+                module = importlib.import_module(module_name)
             except ModuleNotFoundError:
                 module = ModuleType(
                     module_name,
                     doc="Empty module created by pytest's importmode=importlib.",
                 )
+        else:
+            module = modules[module_name]
+        if child_module:
+            # Add child attribute to the parent that can reference the child
+            # modules.
+            if not hasattr(module, child_name):
+                setattr(module, child_name, child_module)
                 modules[module_name] = module
+        # Keep track of the child module while moving up the tree.
+        child_module, child_name = module, module_name.rpartition(".")[-1]
         module_parts.pop(-1)
         module_name = ".".join(module_parts)
 
diff --git a/testing/test_pathlib.py b/testing/test_pathlib.py
index 945d6f7d746..3d574e85658 100644
--- a/testing/test_pathlib.py
+++ b/testing/test_pathlib.py
@@ -603,3 +603,15 @@ def test_insert_missing_modules(
         modules = {}
         insert_missing_modules(modules, "")
         assert modules == {}
+
+    def test_parent_contains_child_module_attribute(
+        self, monkeypatch: MonkeyPatch, tmp_path: Path
+    ):
+        monkeypatch.chdir(tmp_path)
+        # Use 'xxx' and 'xxy' as parent names as they are unlikely to exist and
+        # don't end up being imported.
+        modules = {"xxx.tests.foo": ModuleType("xxx.tests.foo")}
+        insert_missing_modules(modules, "xxx.tests.foo")
+        assert sorted(modules) == ["xxx", "xxx.tests", "xxx.tests.foo"]
+        assert modules["xxx"].tests is modules["xxx.tests"]
+        assert modules["xxx.tests"].foo is modules["xxx.tests.foo"]

From 511adf85beb87c96d6b0c9922a17e3acc4e8713f Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Sat, 8 Jul 2023 18:37:35 +0000
Subject: [PATCH 05/27] [7.4.x] Fix error assertion handling in approx when
 None in dict comparison (#11180)

Co-authored-by: Zac Hatfield-Dodds <zac.hatfield.dodds@gmail.com>
---
 changelog/10702.bugfix.rst |  1 +
 src/_pytest/python_api.py  | 25 +++++++++++++------------
 testing/python/approx.py   | 17 +++++++++++++++++
 3 files changed, 31 insertions(+), 12 deletions(-)
 create mode 100644 changelog/10702.bugfix.rst

diff --git a/changelog/10702.bugfix.rst b/changelog/10702.bugfix.rst
new file mode 100644
index 00000000000..4008cc882ec
--- /dev/null
+++ b/changelog/10702.bugfix.rst
@@ -0,0 +1 @@
+Fixed error assertion handling in :func:`pytest.approx` when ``None`` is an expected or received value when comparing dictionaries.
diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py
index 4213bd098c2..183356100c5 100644
--- a/src/_pytest/python_api.py
+++ b/src/_pytest/python_api.py
@@ -266,19 +266,20 @@ def _repr_compare(self, other_side: Mapping[object, float]) -> List[str]:
             approx_side_as_map.items(), other_side.values()
         ):
             if approx_value != other_value:
-                max_abs_diff = max(
-                    max_abs_diff, abs(approx_value.expected - other_value)
-                )
-                if approx_value.expected == 0.0:
-                    max_rel_diff = math.inf
-                else:
-                    max_rel_diff = max(
-                        max_rel_diff,
-                        abs(
-                            (approx_value.expected - other_value)
-                            / approx_value.expected
-                        ),
+                if approx_value.expected is not None and other_value is not None:
+                    max_abs_diff = max(
+                        max_abs_diff, abs(approx_value.expected - other_value)
                     )
+                    if approx_value.expected == 0.0:
+                        max_rel_diff = math.inf
+                    else:
+                        max_rel_diff = max(
+                            max_rel_diff,
+                            abs(
+                                (approx_value.expected - other_value)
+                                / approx_value.expected
+                            ),
+                        )
                 different_ids.append(approx_key)
 
         message_data = [
diff --git a/testing/python/approx.py b/testing/python/approx.py
index 631e52b56ac..6ad411a3e07 100644
--- a/testing/python/approx.py
+++ b/testing/python/approx.py
@@ -122,6 +122,23 @@ def test_error_messages_native_dtypes(self, assert_approx_raises_regex):
             ],
         )
 
+        assert_approx_raises_regex(
+            {"a": 1.0, "b": None, "c": None},
+            {
+                "a": None,
+                "b": 1000.0,
+                "c": None,
+            },
+            [
+                r"  comparison failed. Mismatched elements: 2 / 3:",
+                r"  Max absolute difference: -inf",
+                r"  Max relative difference: -inf",
+                r"  Index \| Obtained\s+\| Expected\s+",
+                rf"  a     \| {SOME_FLOAT} \| None",
+                rf"  b     \| None\s+\| {SOME_FLOAT} ± {SOME_FLOAT}",
+            ],
+        )
+
         assert_approx_raises_regex(
             [1.0, 2.0, 3.0, 4.0],
             [1.0, 3.0, 3.0, 5.0],

From a566b78730c6ffad5bee5b41c8d615423a56e836 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Sat, 8 Jul 2023 19:07:55 +0000
Subject: [PATCH 06/27] [7.4.x] reference: improve the node types docs a bit
 (#11181)

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
---
 doc/en/reference/reference.rst | 138 ++++++++++++++++++---------------
 src/_pytest/main.py            |   5 ++
 src/_pytest/nodes.py           |  21 +++--
 src/_pytest/python.py          |  15 ++--
 4 files changed, 102 insertions(+), 77 deletions(-)

diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst
index 83bbccbcbdc..9e79397f09d 100644
--- a/doc/en/reference/reference.rst
+++ b/doc/en/reference/reference.rst
@@ -783,25 +783,17 @@ reporting or interaction with exceptions:
 .. autofunction:: pytest_leave_pdb
 
 
-Objects
--------
-
-Full reference to objects accessible from :ref:`fixtures <fixture>` or :ref:`hooks <hook-reference>`.
+Collection tree objects
+-----------------------
 
+These are the collector and item classes (collectively called "nodes") which
+make up the collection tree.
 
-CallInfo
-~~~~~~~~
-
-.. autoclass:: pytest.CallInfo()
-    :members:
-
-
-Class
-~~~~~
+Node
+~~~~
 
-.. autoclass:: pytest.Class()
+.. autoclass:: _pytest.nodes.Node()
     :members:
-    :show-inheritance:
 
 Collector
 ~~~~~~~~~
@@ -810,52 +802,52 @@ Collector
     :members:
     :show-inheritance:
 
-CollectReport
-~~~~~~~~~~~~~
+Item
+~~~~
 
-.. autoclass:: pytest.CollectReport()
+.. autoclass:: pytest.Item()
     :members:
     :show-inheritance:
-    :inherited-members:
 
-Config
-~~~~~~
+File
+~~~~
 
-.. autoclass:: pytest.Config()
+.. autoclass:: pytest.File()
     :members:
+    :show-inheritance:
 
-ExceptionInfo
-~~~~~~~~~~~~~
+FSCollector
+~~~~~~~~~~~
 
-.. autoclass:: pytest.ExceptionInfo()
+.. autoclass:: _pytest.nodes.FSCollector()
     :members:
+    :show-inheritance:
 
+Session
+~~~~~~~
 
-ExitCode
-~~~~~~~~
-
-.. autoclass:: pytest.ExitCode
+.. autoclass:: pytest.Session()
     :members:
+    :show-inheritance:
 
-File
-~~~~
+Package
+~~~~~~~
 
-.. autoclass:: pytest.File()
+.. autoclass:: pytest.Package()
     :members:
     :show-inheritance:
 
+Module
+~~~~~~
 
-FixtureDef
-~~~~~~~~~~
-
-.. autoclass:: _pytest.fixtures.FixtureDef()
+.. autoclass:: pytest.Module()
     :members:
     :show-inheritance:
 
-FSCollector
-~~~~~~~~~~~
+Class
+~~~~~
 
-.. autoclass:: _pytest.nodes.FSCollector()
+.. autoclass:: pytest.Class()
     :members:
     :show-inheritance:
 
@@ -873,10 +865,52 @@ FunctionDefinition
     :members:
     :show-inheritance:
 
-Item
-~~~~
 
-.. autoclass:: pytest.Item()
+Objects
+-------
+
+Objects accessible from :ref:`fixtures <fixture>` or :ref:`hooks <hook-reference>`
+or importable from ``pytest``.
+
+
+CallInfo
+~~~~~~~~
+
+.. autoclass:: pytest.CallInfo()
+    :members:
+
+CollectReport
+~~~~~~~~~~~~~
+
+.. autoclass:: pytest.CollectReport()
+    :members:
+    :show-inheritance:
+    :inherited-members:
+
+Config
+~~~~~~
+
+.. autoclass:: pytest.Config()
+    :members:
+
+ExceptionInfo
+~~~~~~~~~~~~~
+
+.. autoclass:: pytest.ExceptionInfo()
+    :members:
+
+
+ExitCode
+~~~~~~~~
+
+.. autoclass:: pytest.ExitCode
+    :members:
+
+
+FixtureDef
+~~~~~~~~~~
+
+.. autoclass:: _pytest.fixtures.FixtureDef()
     :members:
     :show-inheritance:
 
@@ -907,19 +941,6 @@ Metafunc
 .. autoclass:: pytest.Metafunc()
     :members:
 
-Module
-~~~~~~
-
-.. autoclass:: pytest.Module()
-    :members:
-    :show-inheritance:
-
-Node
-~~~~
-
-.. autoclass:: _pytest.nodes.Node()
-    :members:
-
 Parser
 ~~~~~~
 
@@ -941,13 +962,6 @@ PytestPluginManager
     :inherited-members:
     :show-inheritance:
 
-Session
-~~~~~~~
-
-.. autoclass:: pytest.Session()
-    :members:
-    :show-inheritance:
-
 TestReport
 ~~~~~~~~~~
 
diff --git a/src/_pytest/main.py b/src/_pytest/main.py
index 155d4300e2c..803b95a2033 100644
--- a/src/_pytest/main.py
+++ b/src/_pytest/main.py
@@ -462,6 +462,11 @@ def __missing__(self, path: Path) -> str:
 
 @final
 class Session(nodes.FSCollector):
+    """The root of the collection tree.
+
+    ``Session`` collects the initial paths given as arguments to pytest.
+    """
+
     Interrupted = Interrupted
     Failed = Failed
     # Set on the session by runner.pytest_sessionstart.
diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py
index dbd6b0a4273..667a02b77af 100644
--- a/src/_pytest/nodes.py
+++ b/src/_pytest/nodes.py
@@ -157,10 +157,11 @@ def _create(self, *k, **kw):
 
 
 class Node(metaclass=NodeMeta):
-    """Base class for Collector and Item, the components of the test
-    collection tree.
+    r"""Base class of :class:`Collector` and :class:`Item`, the components of
+    the test collection tree.
 
-    Collector subclasses have children; Items are leaf nodes.
+    ``Collector``\'s are the internal nodes of the tree, and ``Item``\'s are the
+    leaf nodes.
     """
 
     # Implemented in the legacypath plugin.
@@ -525,15 +526,17 @@ def get_fslocation_from_item(node: "Node") -> Tuple[Union[str, Path], Optional[i
 
 
 class Collector(Node):
-    """Collector instances create children through collect() and thus
-    iteratively build a tree."""
+    """Base class of all collectors.
+
+    Collector create children through `collect()` and thus iteratively build
+    the collection tree.
+    """
 
     class CollectError(Exception):
         """An error during collection, contains a custom message."""
 
     def collect(self) -> Iterable[Union["Item", "Collector"]]:
-        """Return a list of children (items and collectors) for this
-        collection node."""
+        """Collect children (items and collectors) for this collector."""
         raise NotImplementedError("abstract")
 
     # TODO: This omits the style= parameter which breaks Liskov Substitution.
@@ -577,6 +580,8 @@ def _check_initialpaths_for_relpath(session: "Session", path: Path) -> Optional[
 
 
 class FSCollector(Collector):
+    """Base class for filesystem collectors."""
+
     def __init__(
         self,
         fspath: Optional[LEGACY_PATH] = None,
@@ -660,7 +665,7 @@ class File(FSCollector):
 
 
 class Item(Node):
-    """A basic test invocation item.
+    """Base class of all test invocation items.
 
     Note that for a single function there might be multiple test invocation items.
     """
diff --git a/src/_pytest/python.py b/src/_pytest/python.py
index ad847c8afe2..b24dc90d8ee 100644
--- a/src/_pytest/python.py
+++ b/src/_pytest/python.py
@@ -522,7 +522,7 @@ def _genfunctions(self, name: str, funcobj) -> Iterator["Function"]:
 
 
 class Module(nodes.File, PyCollector):
-    """Collector for test classes and functions."""
+    """Collector for test classes and functions in a Python module."""
 
     def _getobj(self):
         return self._importtestmodule()
@@ -659,6 +659,9 @@ def _importtestmodule(self):
 
 
 class Package(Module):
+    """Collector for files and directories in a Python packages -- directories
+    with an `__init__.py` file."""
+
     def __init__(
         self,
         fspath: Optional[LEGACY_PATH],
@@ -788,7 +791,7 @@ def _get_first_non_fixture_func(obj: object, names: Iterable[str]) -> Optional[o
 
 
 class Class(PyCollector):
-    """Collector for test methods."""
+    """Collector for test methods (and nested classes) in a Python class."""
 
     @classmethod
     def from_parent(cls, parent, *, name, obj=None, **kw):
@@ -1673,7 +1676,7 @@ def write_docstring(tw: TerminalWriter, doc: str, indent: str = "    ") -> None:
 
 
 class Function(PyobjMixin, nodes.Item):
-    """An Item responsible for setting up and executing a Python test function.
+    """Item responsible for setting up and executing a Python test function.
 
     :param name:
         The full function name, including any decorations like those
@@ -1830,10 +1833,8 @@ def repr_failure(  # type: ignore[override]
 
 
 class FunctionDefinition(Function):
-    """
-    This class is a step gap solution until we evolve to have actual function definition nodes
-    and manage to get rid of ``metafunc``.
-    """
+    """This class is a stop gap solution until we evolve to have actual function
+    definition nodes and manage to get rid of ``metafunc``."""
 
     def runtest(self) -> None:
         raise RuntimeError("function definitions are not supposed to be run as tests")

From 6dfe498c7747483b0e42694f1ae68cf7386c57f6 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Sat, 8 Jul 2023 19:17:21 +0000
Subject: [PATCH 07/27] [7.4.x] doc: fix EncodingWarnings in examples (#11182)

Co-authored-by: Ran Benita <ran@unusedvar.com>
---
 doc/en/example/nonpython/conftest.py | 2 +-
 doc/en/example/simple.rst            | 2 +-
 doc/en/how-to/fixtures.rst           | 2 +-
 doc/en/how-to/tmp_path.rst           | 4 ++--
 doc/en/how-to/unittest.rst           | 4 ++--
 5 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/doc/en/example/nonpython/conftest.py b/doc/en/example/nonpython/conftest.py
index dd1ebe88d7e..e969e3e2518 100644
--- a/doc/en/example/nonpython/conftest.py
+++ b/doc/en/example/nonpython/conftest.py
@@ -12,7 +12,7 @@ def collect(self):
         # We need a yaml parser, e.g. PyYAML.
         import yaml
 
-        raw = yaml.safe_load(self.path.open())
+        raw = yaml.safe_load(self.path.open(encoding="utf-8"))
         for name, spec in sorted(raw.items()):
             yield YamlItem.from_parent(self, name=name, spec=spec)
 
diff --git a/doc/en/example/simple.rst b/doc/en/example/simple.rst
index 97a6dd9f436..32e5188b741 100644
--- a/doc/en/example/simple.rst
+++ b/doc/en/example/simple.rst
@@ -817,7 +817,7 @@ case we just write some information out to a ``failures`` file:
         # we only look at actual failing test calls, not setup/teardown
         if rep.when == "call" and rep.failed:
             mode = "a" if os.path.exists("failures") else "w"
-            with open("failures", mode) as f:
+            with open("failures", mode, encoding="utf-8") as f:
                 # let's also access a fixture for the fun of it
                 if "tmp_path" in item.fixturenames:
                     extra = " ({})".format(item.funcargs["tmp_path"])
diff --git a/doc/en/how-to/fixtures.rst b/doc/en/how-to/fixtures.rst
index d8517c2c8f3..a6f4962f083 100644
--- a/doc/en/how-to/fixtures.rst
+++ b/doc/en/how-to/fixtures.rst
@@ -1698,7 +1698,7 @@ and declare its use in a test module via a ``usefixtures`` marker:
     class TestDirectoryInit:
         def test_cwd_starts_empty(self):
             assert os.listdir(os.getcwd()) == []
-            with open("myfile", "w") as f:
+            with open("myfile", "w", encoding="utf-8") as f:
                 f.write("hello")
 
         def test_cwd_again_starts_empty(self):
diff --git a/doc/en/how-to/tmp_path.rst b/doc/en/how-to/tmp_path.rst
index 792933dd87e..d5573f5847d 100644
--- a/doc/en/how-to/tmp_path.rst
+++ b/doc/en/how-to/tmp_path.rst
@@ -24,8 +24,8 @@ created in the `base temporary directory`_.
         d = tmp_path / "sub"
         d.mkdir()
         p = d / "hello.txt"
-        p.write_text(CONTENT)
-        assert p.read_text() == CONTENT
+        p.write_text(CONTENT, encoding="utf-8")
+        assert p.read_text(encoding="utf-8") == CONTENT
         assert len(list(tmp_path.iterdir())) == 1
         assert 0
 
diff --git a/doc/en/how-to/unittest.rst b/doc/en/how-to/unittest.rst
index 37caf6e9fb7..7856c1a49c0 100644
--- a/doc/en/how-to/unittest.rst
+++ b/doc/en/how-to/unittest.rst
@@ -207,10 +207,10 @@ creation of a per-test temporary directory:
         @pytest.fixture(autouse=True)
         def initdir(self, tmp_path, monkeypatch):
             monkeypatch.chdir(tmp_path)  # change to pytest-provided temporary directory
-            tmp_path.joinpath("samplefile.ini").write_text("# testdata")
+            tmp_path.joinpath("samplefile.ini").write_text("# testdata", encoding="utf-8")
 
         def test_method(self):
-            with open("samplefile.ini") as f:
+            with open("samplefile.ini", encoding="utf-8") as f:
                 s = f.read()
             assert "testdata" in s
 

From 06ff7ca13bfe7f860110a829ed48f3d427e6502c Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Sun, 9 Jul 2023 15:54:59 +0000
Subject: [PATCH 08/27] [7.4.x] Clarify docs for pytest.main default behavior
 (#11188)

Co-authored-by: antosikv <79337398+antosikv@users.noreply.github.com>
---
 doc/en/how-to/usage.rst        | 3 ++-
 src/_pytest/config/__init__.py | 4 +++-
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/doc/en/how-to/usage.rst b/doc/en/how-to/usage.rst
index 8e2dd86736f..4ec4459a232 100644
--- a/doc/en/how-to/usage.rst
+++ b/doc/en/how-to/usage.rst
@@ -173,7 +173,8 @@ You can invoke ``pytest`` from Python code directly:
 
 this acts as if you would call "pytest" from the command line.
 It will not raise :class:`SystemExit` but return the :ref:`exit code <exit-codes>` instead.
-You can pass in options and arguments:
+If you don't pass it any arguments, ``main`` reads the arguments from the command line arguments of the process (:data:`sys.argv`), which may be undesirable.
+You can pass in options and arguments explicitly:
 
 .. code-block:: python
 
diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py
index c9a4b7f63cb..45f4cf831ff 100644
--- a/src/_pytest/config/__init__.py
+++ b/src/_pytest/config/__init__.py
@@ -137,7 +137,9 @@ def main(
 ) -> Union[int, ExitCode]:
     """Perform an in-process test run.
 
-    :param args: List of command line arguments.
+    :param args:
+        List of command line arguments. If `None` or not given, defaults to reading
+        arguments directly from the process command line (:data:`sys.argv`).
     :param plugins: List of plugin objects to be auto-registered during initialization.
 
     :returns: An exit code.

From 350122abb2674f98144b9267b195f3e84a032e66 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Sat, 22 Jul 2023 18:40:56 +0000
Subject: [PATCH 09/27] [7.4.x] Remove ep2023 training (#11242)

Co-authored-by: Florian Bruhin <me@the-compiler.org>
---
 doc/en/index.rst | 1 -
 1 file changed, 1 deletion(-)

diff --git a/doc/en/index.rst b/doc/en/index.rst
index 50f3e9c10c3..69ca1dcfea9 100644
--- a/doc/en/index.rst
+++ b/doc/en/index.rst
@@ -2,7 +2,6 @@
 
 .. sidebar:: Next Open Trainings
 
-   - `pytest tips and tricks for a better testsuite <https://ep2023.europython.eu/session/pytest-tips-and-tricks-for-a-better-testsuite>`_, at `Europython 2023 <https://ep2023.europython.eu/>`_, **July 18th** (3h), **Prague, Czech Republic / Remote**
    - `pytest: Professionelles Testen (nicht nur) für Python <https://workshoptage.ch/workshops/2023/pytest-professionelles-testen-nicht-nur-fuer-python-2/>`_, at `Workshoptage 2023 <https://workshoptage.ch/>`_, **September 5th**, `OST <https://www.ost.ch/en>`_ Campus **Rapperswil, Switzerland**
    - `Professional Testing with Python <https://python-academy.com/courses/python_course_testing.html>`_, via `Python Academy <https://www.python-academy.com/>`_, **March 5th to 7th 2024** (3 day in-depth training), **Leipzig, Germany / Remote**
 

From 34c73944e1d8e89a802a82a71ed75efcd1ee6700 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Mon, 7 Aug 2023 10:47:12 +0200
Subject: [PATCH 10/27] [7.4.x] doc: update information about assertion
 messages (#11286)

Co-authored-by: Christoph Anton Mitterer <mail@christoph.anton.mitterer.name>
---
 doc/en/how-to/assert.rst | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/doc/en/how-to/assert.rst b/doc/en/how-to/assert.rst
index 1b10c131389..d99a1ce5c97 100644
--- a/doc/en/how-to/assert.rst
+++ b/doc/en/how-to/assert.rst
@@ -54,14 +54,13 @@ operators. (See :ref:`tbreportdemo`).  This allows you to use the
 idiomatic python constructs without boilerplate code while not losing
 introspection information.
 
-However, if you specify a message with the assertion like this:
+If a message is specified with the assertion like this:
 
 .. code-block:: python
 
     assert a % 2 == 0, "value was odd, should be even"
 
-then no assertion introspection takes places at all and the message
-will be simply shown in the traceback.
+it is printed alongside the assertion introspection in the traceback.
 
 See :ref:`assert-details` for more information on assertion introspection.
 

From e3fe7286f803cff00314b64ffaaedd5cfc9a6b8f Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Mon, 7 Aug 2023 10:47:37 +0200
Subject: [PATCH 11/27] [7.4.x] doc: Link pytest.main to how-to guide (#11290)

Co-authored-by: Florian Bruhin <me@the-compiler.org>
---
 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 9e79397f09d..767f8a8f3d3 100644
--- a/doc/en/reference/reference.rst
+++ b/doc/en/reference/reference.rst
@@ -82,6 +82,8 @@ pytest.exit
 pytest.main
 ~~~~~~~~~~~
 
+**Tutorial**: :ref:`pytest.main-usage`
+
 .. autofunction:: pytest.main
 
 pytest.param

From ba40975bb72e8b2ba749a06ccffef42638f8800a Mon Sep 17 00:00:00 2001
From: Florian Bruhin <me@the-compiler.org>
Date: Mon, 7 Aug 2023 12:08:56 +0200
Subject: [PATCH 12/27] ci: Use Python 3.8 to test latest pluggy

Pluggy dropped Python 3.7 support.
Also see 165fbbd12a74ab639d61ce1f28dfef1511a2c2e2

Fixes #11293
---
 .github/workflows/test.yml | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index cf5027223e1..eb2dfa85d26 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -38,17 +38,17 @@ jobs:
       matrix:
         name: [
           "windows-py37",
-          "windows-py37-pluggy",
           "windows-py38",
+          "windows-py38-pluggy",
           "windows-py39",
           "windows-py310",
           "windows-py311",
           "windows-py312",
 
           "ubuntu-py37",
-          "ubuntu-py37-pluggy",
           "ubuntu-py37-freeze",
           "ubuntu-py38",
+          "ubuntu-py38-pluggy",
           "ubuntu-py39",
           "ubuntu-py310",
           "ubuntu-py311",
@@ -70,15 +70,15 @@ jobs:
             python: "3.7"
             os: windows-latest
             tox_env: "py37-numpy"
-          - name: "windows-py37-pluggy"
-            python: "3.7"
-            os: windows-latest
-            tox_env: "py37-pluggymain-pylib-xdist"
           - name: "windows-py38"
             python: "3.8"
             os: windows-latest
             tox_env: "py38-unittestextras"
             use_coverage: true
+          - name: "windows-py38-pluggy"
+            python: "3.8"
+            os: windows-latest
+            tox_env: "py38-pluggymain-pylib-xdist"
           - name: "windows-py39"
             python: "3.9"
             os: windows-latest
@@ -101,10 +101,6 @@ jobs:
             os: ubuntu-latest
             tox_env: "py37-lsof-numpy-pexpect"
             use_coverage: true
-          - name: "ubuntu-py37-pluggy"
-            python: "3.7"
-            os: ubuntu-latest
-            tox_env: "py37-pluggymain-pylib-xdist"
           - name: "ubuntu-py37-freeze"
             python: "3.7"
             os: ubuntu-latest
@@ -113,6 +109,10 @@ jobs:
             python: "3.8"
             os: ubuntu-latest
             tox_env: "py38-xdist"
+          - name: "ubuntu-py38-pluggy"
+            python: "3.8"
+            os: ubuntu-latest
+            tox_env: "py38-pluggymain-pylib-xdist"
           - name: "ubuntu-py39"
             python: "3.9"
             os: ubuntu-latest

From 69140717d468cf93750c3f54254ca960455bfd1a Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Tue, 8 Aug 2023 14:44:03 +0300
Subject: [PATCH 13/27] [7.4.x] Improve duplicate values documentation (#11296)

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
---
 src/_pytest/python.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/_pytest/python.py b/src/_pytest/python.py
index b24dc90d8ee..5f8be5d9b9e 100644
--- a/src/_pytest/python.py
+++ b/src/_pytest/python.py
@@ -1152,7 +1152,7 @@ def setmulti(
         arg2scope = self._arg2scope.copy()
         for arg, val in zip(argnames, valset):
             if arg in params or arg in funcargs:
-                raise ValueError(f"duplicate {arg!r}")
+                raise ValueError(f"duplicate parametrization of {arg!r}")
             valtype_for_arg = valtypes[arg]
             if valtype_for_arg == "params":
                 params[arg] = val
@@ -1243,8 +1243,9 @@ def parametrize(
         during the collection phase. If you need to setup expensive resources
         see about setting indirect to do it rather than at test setup time.
 
-        Can be called multiple times, in which case each call parametrizes all
-        previous parametrizations, e.g.
+        Can be called multiple times per test function (but only on different
+        argument names), in which case each call parametrizes all previous
+        parametrizations, e.g.
 
         ::
 

From 7a5f2feefbbb976b1c5b4ced18e7e6725edfd3d5 Mon Sep 17 00:00:00 2001
From: Ran Benita <ran@unusedvar.com>
Date: Sun, 27 Aug 2023 01:15:32 +0300
Subject: [PATCH 14/27] [7.4.x] Fixes for typed pluggy (#11355)

Since version 1.3 pluggy added typing, which requires some fixes to
please mypy.
---
 doc/en/reference/reference.rst |  4 ++--
 src/_pytest/config/__init__.py | 13 +++++++------
 src/_pytest/helpconfig.py      |  6 +++++-
 src/_pytest/logging.py         |  2 ++
 src/_pytest/pytester.py        |  2 +-
 testing/test_pluginmanager.py  | 10 ++++++++--
 6 files changed, 25 insertions(+), 12 deletions(-)

diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst
index 767f8a8f3d3..38b58b5c4c7 100644
--- a/doc/en/reference/reference.rst
+++ b/doc/en/reference/reference.rst
@@ -978,10 +978,10 @@ TestShortLogReport
 .. autoclass:: pytest.TestShortLogReport()
     :members:
 
-_Result
+Result
 ~~~~~~~
 
-Result object used within :ref:`hook wrappers <hookwrapper>`, see :py:class:`_Result in the pluggy documentation <pluggy._callers._Result>` for more information.
+Result object used within :ref:`hook wrappers <hookwrapper>`, see :py:class:`Result in the pluggy documentation <pluggy.Result>` for more information.
 
 Stash
 ~~~~~
diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py
index 45f4cf831ff..dc2b9f6a160 100644
--- a/src/_pytest/config/__init__.py
+++ b/src/_pytest/config/__init__.py
@@ -444,10 +444,10 @@ def parse_hookimpl_opts(self, plugin: _PluggyPlugin, name: str):
         # so we avoid accessing possibly non-readable attributes
         # (see issue #1073).
         if not name.startswith("pytest_"):
-            return
+            return None
         # Ignore names which can not be hooks.
         if name == "pytest_plugins":
-            return
+            return None
 
         opts = super().parse_hookimpl_opts(plugin, name)
         if opts is not None:
@@ -456,9 +456,9 @@ def parse_hookimpl_opts(self, plugin: _PluggyPlugin, name: str):
         method = getattr(plugin, name)
         # Consider only actual functions for hooks (#3775).
         if not inspect.isroutine(method):
-            return
+            return None
         # Collect unmarked hooks as long as they have the `pytest_' prefix.
-        return _get_legacy_hook_marks(
+        return _get_legacy_hook_marks(  # type: ignore[return-value]
             method, "impl", ("tryfirst", "trylast", "optionalhook", "hookwrapper")
         )
 
@@ -467,7 +467,7 @@ def parse_hookspec_opts(self, module_or_class, name: str):
         if opts is None:
             method = getattr(module_or_class, name)
             if name.startswith("pytest_"):
-                opts = _get_legacy_hook_marks(
+                opts = _get_legacy_hook_marks(  # type: ignore[assignment]
                     method,
                     "spec",
                     ("firstresult", "historic"),
@@ -1065,9 +1065,10 @@ def _ensure_unconfigure(self) -> None:
             fin()
 
     def get_terminal_writer(self) -> TerminalWriter:
-        terminalreporter: TerminalReporter = self.pluginmanager.get_plugin(
+        terminalreporter: Optional[TerminalReporter] = self.pluginmanager.get_plugin(
             "terminalreporter"
         )
+        assert terminalreporter is not None
         return terminalreporter._tw
 
     def pytest_cmdline_parse(
diff --git a/src/_pytest/helpconfig.py b/src/_pytest/helpconfig.py
index 430870608bd..ea16c438823 100644
--- a/src/_pytest/helpconfig.py
+++ b/src/_pytest/helpconfig.py
@@ -11,6 +11,7 @@
 from _pytest.config import ExitCode
 from _pytest.config import PrintHelp
 from _pytest.config.argparsing import Parser
+from _pytest.terminal import TerminalReporter
 
 
 class HelpAction(Action):
@@ -159,7 +160,10 @@ def pytest_cmdline_main(config: Config) -> Optional[Union[int, ExitCode]]:
 def showhelp(config: Config) -> None:
     import textwrap
 
-    reporter = config.pluginmanager.get_plugin("terminalreporter")
+    reporter: Optional[TerminalReporter] = config.pluginmanager.get_plugin(
+        "terminalreporter"
+    )
+    assert reporter is not None
     tw = reporter._tw
     tw.write(config._parser.optparser.format_help())
     tw.line()
diff --git a/src/_pytest/logging.py b/src/_pytest/logging.py
index 83813466016..9f2f1c79359 100644
--- a/src/_pytest/logging.py
+++ b/src/_pytest/logging.py
@@ -660,6 +660,8 @@ def __init__(self, config: Config) -> None:
         )
         if self._log_cli_enabled():
             terminal_reporter = config.pluginmanager.get_plugin("terminalreporter")
+            # Guaranteed by `_log_cli_enabled()`.
+            assert terminal_reporter is not None
             capture_manager = config.pluginmanager.get_plugin("capturemanager")
             # if capturemanager plugin is disabled, live logging still works.
             self.log_cli_handler: Union[
diff --git a/src/_pytest/pytester.py b/src/_pytest/pytester.py
index 3df52ebe88c..cdfc2c04ae1 100644
--- a/src/_pytest/pytester.py
+++ b/src/_pytest/pytester.py
@@ -752,7 +752,7 @@ def preserve_module(name):
 
     def make_hook_recorder(self, pluginmanager: PytestPluginManager) -> HookRecorder:
         """Create a new :class:`HookRecorder` for a :class:`PytestPluginManager`."""
-        pluginmanager.reprec = reprec = HookRecorder(pluginmanager, _ispytest=True)
+        pluginmanager.reprec = reprec = HookRecorder(pluginmanager, _ispytest=True)  # type: ignore[attr-defined]
         self._request.addfinalizer(reprec.finish_recording)
         return reprec
 
diff --git a/testing/test_pluginmanager.py b/testing/test_pluginmanager.py
index c6f518b1da2..e5773412fbf 100644
--- a/testing/test_pluginmanager.py
+++ b/testing/test_pluginmanager.py
@@ -242,8 +242,12 @@ def test_consider_module(
         mod = types.ModuleType("temp")
         mod.__dict__["pytest_plugins"] = ["pytest_p1", "pytest_p2"]
         pytestpm.consider_module(mod)
-        assert pytestpm.get_plugin("pytest_p1").__name__ == "pytest_p1"
-        assert pytestpm.get_plugin("pytest_p2").__name__ == "pytest_p2"
+        p1 = pytestpm.get_plugin("pytest_p1")
+        assert p1 is not None
+        assert p1.__name__ == "pytest_p1"
+        p2 = pytestpm.get_plugin("pytest_p2")
+        assert p2 is not None
+        assert p2.__name__ == "pytest_p2"
 
     def test_consider_module_import_module(
         self, pytester: Pytester, _config_for_test: Config
@@ -336,6 +340,7 @@ def test_import_plugin_importname(
         len2 = len(pytestpm.get_plugins())
         assert len1 == len2
         plugin1 = pytestpm.get_plugin("pytest_hello")
+        assert plugin1 is not None
         assert plugin1.__name__.endswith("pytest_hello")
         plugin2 = pytestpm.get_plugin("pytest_hello")
         assert plugin2 is plugin1
@@ -351,6 +356,7 @@ def test_import_plugin_dotted_name(
         pluginname = "pkg.plug"
         pytestpm.import_plugin(pluginname)
         mod = pytestpm.get_plugin("pkg.plug")
+        assert mod is not None
         assert mod.x == 3
 
     def test_consider_conftest_deps(

From b170081788ad51a2ccf5d47205e69f98bf6f574d Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Tue, 29 Aug 2023 00:40:49 +0000
Subject: [PATCH 15/27] [7.4.x] Issue 11354 fixing docs for lfnf (#11364)

Co-authored-by: Sean Patrick Malloy <spmalloy@ucdavis.edu>
---
 doc/en/how-to/cache.rst        | 17 ++++++++++++-----
 doc/en/reference/reference.rst |  7 +++++--
 src/_pytest/cacheprovider.py   |  6 +++++-
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/doc/en/how-to/cache.rst b/doc/en/how-to/cache.rst
index 8554a984c72..03ab0c77780 100644
--- a/doc/en/how-to/cache.rst
+++ b/doc/en/how-to/cache.rst
@@ -176,14 +176,21 @@ with more recent files coming first.
 Behavior when no tests failed in the last run
 ---------------------------------------------
 
-When no tests failed in the last run, or when no cached ``lastfailed`` data was
-found, ``pytest`` can be configured either to run all of the tests or no tests,
-using the ``--last-failed-no-failures`` option, which takes one of the following values:
+The ``--lfnf/--last-failed-no-failures`` option governs the behavior of ``--last-failed``.
+Determines whether to execute tests when there are no previously (known)
+failures or when no cached ``lastfailed`` data was found.
+
+There are two options:
+
+* ``all``:  when there are no known test failures, runs all tests (the full test suite). This is the default.
+* ``none``: when there are no known test failures, just emits a message stating this and exit successfully.
+
+Example:
 
 .. code-block:: bash
 
-    pytest --last-failed --last-failed-no-failures all    # run all tests (default behavior)
-    pytest --last-failed --last-failed-no-failures none   # run no tests and exit
+    pytest --last-failed --last-failed-no-failures all    # runs the full test suite (default behavior)
+    pytest --last-failed --last-failed-no-failures none   # runs no tests and exits successfully
 
 The new config.cache object
 --------------------------------
diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst
index 38b58b5c4c7..ef7e19c03d0 100644
--- a/doc/en/reference/reference.rst
+++ b/doc/en/reference/reference.rst
@@ -1887,8 +1887,11 @@ All the command-line flags can be obtained by running ``pytest --help``::
                             tests. Optional argument: glob (default: '*').
       --cache-clear         Remove all cache contents at start of test run
       --lfnf={all,none}, --last-failed-no-failures={all,none}
-                            Which tests to run with no previously (known)
-                            failures
+                            With ``--lf``, determines whether to execute tests when there
+                            are no previously (known) failures or when no
+                            cached ``lastfailed`` data was found.
+                            ``all`` (the default) runs the full test suite again.
+                            ``none`` just emits a message about no known failures and exits successfully.
       --sw, --stepwise      Exit on test failure and continue from last failing
                             test next time
       --sw-skip, --stepwise-skip
diff --git a/src/_pytest/cacheprovider.py b/src/_pytest/cacheprovider.py
index 855716d8199..1ecb8650580 100755
--- a/src/_pytest/cacheprovider.py
+++ b/src/_pytest/cacheprovider.py
@@ -505,7 +505,11 @@ def pytest_addoption(parser: Parser) -> None:
         dest="last_failed_no_failures",
         choices=("all", "none"),
         default="all",
-        help="Which tests to run with no previously (known) failures",
+        help="With ``--lf``, determines whether to execute tests when there "
+        "are no previously (known) failures or when no "
+        "cached ``lastfailed`` data was found. "
+        "``all`` (the default) runs the full test suite again. "
+        "``none`` just emits a message about no known failures and exits successfully.",
     )
 
 

From fbcfd3a52e1c64349e143aa8b146ac1a71340c68 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Wed, 30 Aug 2023 08:57:49 -0300
Subject: [PATCH 16/27] [7.4.x] Update CONTRIBUTING.rst (#11371)

Co-authored-by: Sourabh Beniwal <sourabhbeniwal@outlook.com>
---
 CONTRIBUTING.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 791f988306f..5ccc66bf5c4 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -50,7 +50,7 @@ Fix bugs
 --------
 
 Look through the `GitHub issues for bugs <https://github.com/pytest-dev/pytest/labels/type:%20bug>`_.
-See also the `"status: easy" issues <https://github.com/pytest-dev/pytest/labels/status%3A%20easy>`_
+See also the `"good first issue" issues <https://github.com/pytest-dev/pytest/labels/good%20first%20issue>`_
 that are friendly to new contributors.
 
 :ref:`Talk <contact>` to developers to find out how you can fix specific bugs. To indicate that you are going

From 7a0a0e8b0857a7194001f4860af3fbc0968765ff Mon Sep 17 00:00:00 2001
From: pytest bot <pytestbot@gmail.com>
Date: Sat, 2 Sep 2023 11:03:06 +0000
Subject: [PATCH 17/27] Prepare release version 7.4.1

---
 changelog/10337.bugfix.rst        |  2 --
 changelog/10702.bugfix.rst        |  1 -
 changelog/10811.bugfix.rst        |  2 --
 doc/en/announce/index.rst         |  1 +
 doc/en/announce/release-7.4.1.rst | 20 ++++++++++++++++++++
 doc/en/builtin.rst                |  2 +-
 doc/en/changelog.rst              | 17 +++++++++++++++++
 doc/en/example/reportingdemo.rst  | 20 ++++++++++----------
 doc/en/getting-started.rst        |  2 +-
 doc/en/how-to/tmp_path.rst        |  4 ++--
 doc/en/reference/reference.rst    | 11 ++++++-----
 11 files changed, 58 insertions(+), 24 deletions(-)
 delete mode 100644 changelog/10337.bugfix.rst
 delete mode 100644 changelog/10702.bugfix.rst
 delete mode 100644 changelog/10811.bugfix.rst
 create mode 100644 doc/en/announce/release-7.4.1.rst

diff --git a/changelog/10337.bugfix.rst b/changelog/10337.bugfix.rst
deleted file mode 100644
index 3270016f926..00000000000
--- a/changelog/10337.bugfix.rst
+++ /dev/null
@@ -1,2 +0,0 @@
-Fixed bug where fake intermediate modules generated by ``--import-mode=importlib`` would not include the
-child modules as attributes of the parent modules.
diff --git a/changelog/10702.bugfix.rst b/changelog/10702.bugfix.rst
deleted file mode 100644
index 4008cc882ec..00000000000
--- a/changelog/10702.bugfix.rst
+++ /dev/null
@@ -1 +0,0 @@
-Fixed error assertion handling in :func:`pytest.approx` when ``None`` is an expected or received value when comparing dictionaries.
diff --git a/changelog/10811.bugfix.rst b/changelog/10811.bugfix.rst
deleted file mode 100644
index aa26414e457..00000000000
--- a/changelog/10811.bugfix.rst
+++ /dev/null
@@ -1,2 +0,0 @@
-Fixed issue when using ``--import-mode=importlib`` together with ``--doctest-modules`` that caused modules
-to be imported more than once, causing problems with modules that have import side effects.
diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst
index 914e763bd9e..85dfa0894fe 100644
--- a/doc/en/announce/index.rst
+++ b/doc/en/announce/index.rst
@@ -6,6 +6,7 @@ Release announcements
    :maxdepth: 2
 
 
+   release-7.4.1
    release-7.4.0
    release-7.3.2
    release-7.3.1
diff --git a/doc/en/announce/release-7.4.1.rst b/doc/en/announce/release-7.4.1.rst
new file mode 100644
index 00000000000..efadcf919e8
--- /dev/null
+++ b/doc/en/announce/release-7.4.1.rst
@@ -0,0 +1,20 @@
+pytest-7.4.1
+=======================================
+
+pytest 7.4.1 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
+* Florian Bruhin
+* Ran Benita
+
+
+Happy testing,
+The pytest Development Team
diff --git a/doc/en/builtin.rst b/doc/en/builtin.rst
index 53305eecded..0d673d0426e 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:528
+    cache -- .../_pytest/cacheprovider.py:532
         Return a cache object that can persist state between testing sessions.
 
         cache.get(key, default)
diff --git a/doc/en/changelog.rst b/doc/en/changelog.rst
index 391721df34d..be7e7fabaef 100644
--- a/doc/en/changelog.rst
+++ b/doc/en/changelog.rst
@@ -28,6 +28,23 @@ with advance notice in the **Deprecations** section of releases.
 
 .. towncrier release notes start
 
+pytest 7.4.1 (2023-09-02)
+=========================
+
+Bug Fixes
+---------
+
+- `#10337 <https://github.com/pytest-dev/pytest/issues/10337>`_: Fixed bug where fake intermediate modules generated by ``--import-mode=importlib`` would not include the
+  child modules as attributes of the parent modules.
+
+
+- `#10702 <https://github.com/pytest-dev/pytest/issues/10702>`_: Fixed error assertion handling in :func:`pytest.approx` when ``None`` is an expected or received value when comparing dictionaries.
+
+
+- `#10811 <https://github.com/pytest-dev/pytest/issues/10811>`_: Fixed issue when using ``--import-mode=importlib`` together with ``--doctest-modules`` that caused modules
+  to be imported more than once, causing problems with modules that have import side effects.
+
+
 pytest 7.4.0 (2023-06-23)
 =========================
 
diff --git a/doc/en/example/reportingdemo.rst b/doc/en/example/reportingdemo.rst
index cb59c4b42e1..d4d3d3ce202 100644
--- a/doc/en/example/reportingdemo.rst
+++ b/doc/en/example/reportingdemo.rst
@@ -554,13 +554,13 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     E       AssertionError: assert False
     E        +  where False = <built-in method startswith of str object at 0xdeadbeef0027>('456')
     E        +    where <built-in method startswith of str object at 0xdeadbeef0027> = '123'.startswith
-    E        +      where '123' = <function TestMoreErrors.test_startswith_nested.<locals>.f at 0xdeadbeef0029>()
-    E        +    and   '456' = <function TestMoreErrors.test_startswith_nested.<locals>.g at 0xdeadbeef002a>()
+    E        +      where '123' = <function TestMoreErrors.test_startswith_nested.<locals>.f at 0xdeadbeef0006>()
+    E        +    and   '456' = <function TestMoreErrors.test_startswith_nested.<locals>.g at 0xdeadbeef0029>()
 
     failure_demo.py:235: AssertionError
     _____________________ TestMoreErrors.test_global_func ______________________
 
-    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002b>
+    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002a>
 
         def test_global_func(self):
     >       assert isinstance(globf(42), float)
@@ -571,18 +571,18 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     failure_demo.py:238: AssertionError
     _______________________ TestMoreErrors.test_instance _______________________
 
-    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002c>
+    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002b>
 
         def test_instance(self):
             self.x = 6 * 7
     >       assert self.x != 42
     E       assert 42 != 42
-    E        +  where 42 = <failure_demo.TestMoreErrors object at 0xdeadbeef002c>.x
+    E        +  where 42 = <failure_demo.TestMoreErrors object at 0xdeadbeef002b>.x
 
     failure_demo.py:242: AssertionError
     _______________________ TestMoreErrors.test_compare ________________________
 
-    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002d>
+    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002c>
 
         def test_compare(self):
     >       assert globf(10) < 5
@@ -592,7 +592,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     failure_demo.py:245: AssertionError
     _____________________ TestMoreErrors.test_try_finally ______________________
 
-    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002e>
+    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002d>
 
         def test_try_finally(self):
             x = 1
@@ -603,7 +603,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     failure_demo.py:250: AssertionError
     ___________________ TestCustomAssertMsg.test_single_line ___________________
 
-    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef002f>
+    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef002e>
 
         def test_single_line(self):
             class A:
@@ -618,7 +618,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     failure_demo.py:261: AssertionError
     ____________________ TestCustomAssertMsg.test_multiline ____________________
 
-    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef0030>
+    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef002f>
 
         def test_multiline(self):
             class A:
@@ -637,7 +637,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     failure_demo.py:268: AssertionError
     ___________________ TestCustomAssertMsg.test_custom_repr ___________________
 
-    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef0031>
+    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef0030>
 
         def test_custom_repr(self):
             class JSON:
diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst
index e295c180454..31cfa68bf38 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.0
+    pytest 7.4.1
 
 .. _`simpletest`:
 
diff --git a/doc/en/how-to/tmp_path.rst b/doc/en/how-to/tmp_path.rst
index d5573f5847d..3b49d63a5be 100644
--- a/doc/en/how-to/tmp_path.rst
+++ b/doc/en/how-to/tmp_path.rst
@@ -51,8 +51,8 @@ Running this would result in a passed test except for the last
             d = tmp_path / "sub"
             d.mkdir()
             p = d / "hello.txt"
-            p.write_text(CONTENT)
-            assert p.read_text() == CONTENT
+            p.write_text(CONTENT, encoding="utf-8")
+            assert p.read_text(encoding="utf-8") == CONTENT
             assert len(list(tmp_path.iterdir())) == 1
     >       assert 0
     E       assert 0
diff --git a/doc/en/reference/reference.rst b/doc/en/reference/reference.rst
index ef7e19c03d0..6e11d385d12 100644
--- a/doc/en/reference/reference.rst
+++ b/doc/en/reference/reference.rst
@@ -1887,11 +1887,12 @@ All the command-line flags can be obtained by running ``pytest --help``::
                             tests. Optional argument: glob (default: '*').
       --cache-clear         Remove all cache contents at start of test run
       --lfnf={all,none}, --last-failed-no-failures={all,none}
-                            With ``--lf``, determines whether to execute tests when there
-                            are no previously (known) failures or when no
-                            cached ``lastfailed`` data was found.
-                            ``all`` (the default) runs the full test suite again.
-                            ``none`` just emits a message about no known failures and exits successfully.
+                            With ``--lf``, determines whether to execute tests
+                            when there are no previously (known) failures or
+                            when no cached ``lastfailed`` data was found.
+                            ``all`` (the default) runs the full test suite
+                            again. ``none`` just emits a message about no known
+                            failures and exits successfully.
       --sw, --stepwise      Exit on test failure and continue from last failing
                             test next time
       --sw-skip, --stepwise-skip

From 7855a72d2c5c810a025460f135ffdd77160bb091 Mon Sep 17 00:00:00 2001
From: Bruno Oliveira <bruno@soliv.dev>
Date: Sat, 2 Sep 2023 08:13:00 -0300
Subject: [PATCH 18/27] Improve CI workflow

* Build the package only once, and test on all platforms.
* Deploy is now triggered manually via an Action, which is then responsible for tagging the repository after the package has been uploaded successfully.
* Drop 'docs': we nowadays rely on readthedocs preview PR builds.
---
 .github/workflows/deploy.yml | 33 +++++++++++++++++++++++----------
 .github/workflows/test.yml   | 36 ++++++++++++++++++++++--------------
 RELEASING.rst                | 11 ++++-------
 3 files changed, 49 insertions(+), 31 deletions(-)

diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index e6b4f0ea2d7..34145271c34 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -1,33 +1,38 @@
 name: deploy
 
 on:
-  push:
-    tags:
-      # These tags are protected, see:
-      # https://github.com/pytest-dev/pytest/settings/tag_protection
-      - "[0-9]+.[0-9]+.[0-9]+"
-      - "[0-9]+.[0-9]+.[0-9]+rc[0-9]+"
+  workflow_dispatch:
+    inputs:
+      version:
+        description: 'Release version'
+        required: true
+        default: '1.2.3'
 
 
 # Set permissions at the job level.
 permissions: {}
 
 jobs:
-  build:
+  package:
     runs-on: ubuntu-latest
+    env:
+      SETUPTOOLS_SCM_PRETEND_VERSION: ${{ github.event.inputs.version }}
     timeout-minutes: 10
+
     steps:
     - uses: actions/checkout@v3
       with:
         fetch-depth: 0
         persist-credentials: false
+
     - name: Build and Check Package
       uses: hynek/build-and-inspect-python-package@v1.5
 
   deploy:
     if: github.repository == 'pytest-dev/pytest'
-    needs: [build]
+    needs: [package]
     runs-on: ubuntu-latest
+    environment: deploy
     timeout-minutes: 30
     permissions:
       id-token: write
@@ -37,9 +42,17 @@ jobs:
       with:
         name: Packages
         path: dist
+
     - name: Publish package to PyPI
       uses: pypa/gh-action-pypi-publish@v1.8.5
 
+    - name: Push tag
+      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 }}
+
   release-notes:
 
     # todo: generate the content in the build  job
@@ -55,11 +68,11 @@ jobs:
       with:
         fetch-depth: 0
         persist-credentials: false
+
     - name: Set up Python
       uses: actions/setup-python@v4
       with:
-        python-version: "3.7"
-
+        python-version: "3.10"
 
     - name: Install tox
       run: |
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index eb2dfa85d26..a3c2d9ed5a1 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -27,7 +27,19 @@ concurrency:
 permissions: {}
 
 jobs:
+  package:
+    runs-on: ubuntu-latest
+    steps:
+    - uses: actions/checkout@v3
+      with:
+        fetch-depth: 0
+        persist-credentials: false
+    - name: Build and Check Package
+      uses: hynek/build-and-inspect-python-package@v1.5
+
   build:
+    needs: [package]
+
     runs-on: ${{ matrix.os }}
     timeout-minutes: 45
     permissions:
@@ -60,7 +72,6 @@ jobs:
           "macos-py310",
           "macos-py312",
 
-          "docs",
           "doctesting",
           "plugins",
         ]
@@ -159,10 +170,6 @@ jobs:
             os: ubuntu-latest
             tox_env: "plugins"
 
-          - name: "docs"
-            python: "3.7"
-            os: ubuntu-latest
-            tox_env: "docs"
           - name: "doctesting"
             python: "3.7"
             os: ubuntu-latest
@@ -175,6 +182,12 @@ jobs:
         fetch-depth: 0
         persist-credentials: false
 
+    - name: Download Package
+      uses: actions/download-artifact@v3
+      with:
+        name: Packages
+        path: dist
+
     - name: Set up Python ${{ matrix.python }}
       uses: actions/setup-python@v4
       with:
@@ -188,11 +201,13 @@ jobs:
 
     - name: Test without coverage
       if: "! matrix.use_coverage"
-      run: "tox -e ${{ matrix.tox_env }}"
+      shell: bash
+      run: tox run -e ${{ matrix.tox_env }} --installpkg `find dist/*.tar.gz`
 
     - name: Test with coverage
       if: "matrix.use_coverage"
-      run: "tox -e ${{ matrix.tox_env }}-coverage"
+      shell: bash
+      run: tox run -e ${{ matrix.tox_env }}-coverage --installpkg `find dist/*.tar.gz`
 
     - name: Generate coverage report
       if: "matrix.use_coverage"
@@ -206,10 +221,3 @@ jobs:
         fail_ci_if_error: true
         files: ./coverage.xml
         verbose: true
-
-  check-package:
-    runs-on: ubuntu-latest
-    steps:
-    - uses: actions/checkout@v3
-    - name: Build and Check Package
-      uses: hynek/build-and-inspect-python-package@v1.5
diff --git a/RELEASING.rst b/RELEASING.rst
index b018dc48932..5d49fb5d6d9 100644
--- a/RELEASING.rst
+++ b/RELEASING.rst
@@ -133,14 +133,11 @@ Releasing
 
 Both automatic and manual processes described above follow the same steps from this point onward.
 
-#. After all tests pass and the PR has been approved, tag the release commit
-   in the ``release-MAJOR.MINOR.PATCH`` branch and push it. This will publish to PyPI::
+#. After all tests pass and the PR has been approved, trigger the ``deploy`` job
+   in https://github.com/pytest-dev/pytest/actions/workflows/deploy.yml.
 
-     git fetch upstream
-     git tag MAJOR.MINOR.PATCH upstream/release-MAJOR.MINOR.PATCH
-     git push upstream MAJOR.MINOR.PATCH
-
-   Wait for the deploy to complete, then make sure it is `available on PyPI <https://pypi.org/project/pytest>`_.
+   This job will require approval from ``pytest-dev/core``, after which it will publish to PyPI
+   and tag the repository.
 
 #. Merge the PR. **Make sure it's not squash-merged**, so that the tagged commit ends up in the main branch.
 

From 0319a0d4fd9ef432a52cfeed69d32f86e6aa9b31 Mon Sep 17 00:00:00 2001
From: Bruno Oliveira <bruno@soliv.dev>
Date: Sat, 2 Sep 2023 12:38:39 -0300
Subject: [PATCH 19/27] Checkout source code during deploy

We need the checked out repository in order to push the tag.
---
 .github/workflows/deploy.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml
index 34145271c34..4cda08650ad 100644
--- a/.github/workflows/deploy.yml
+++ b/.github/workflows/deploy.yml
@@ -37,6 +37,7 @@ jobs:
     permissions:
       id-token: write
     steps:
+    - uses: actions/checkout@v3
     - name: Download Package
       uses: actions/download-artifact@v3
       with:

From 7f5d9b9df4e5e323fe3a66aeb956557710e5d277 Mon Sep 17 00:00:00 2001
From: Bruno Oliveira <nicoddemus@gmail.com>
Date: Sun, 3 Sep 2023 15:01:56 -0300
Subject: [PATCH 20/27] Fix user_properties not saved to XML if fixture errors
 during teardown (#11382)

Move handling of user_properties to `finalize()`.

Previously if a fixture failed during teardown, `pytest_runtest_logreport` would not be called with "teardown", resulting in the user properties not being saved on the JUnit XML file.

Fixes: #11367
(cherry picked from commit 917ce9aa0102c7f0ec8fdac118058c41ffb603e6)

Co-authored-by: Israel Fruchter <israel.fruchter@gmail.com>
---
 AUTHORS                    |  2 ++
 changelog/11367.bugfix.rst |  1 +
 src/_pytest/junitxml.py    |  7 ++++---
 testing/test_junitxml.py   | 30 ++++++++++++++++++++++++++++++
 4 files changed, 37 insertions(+), 3 deletions(-)
 create mode 100644 changelog/11367.bugfix.rst

diff --git a/AUTHORS b/AUTHORS
index ee4ef203f0c..d914f3ba906 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -166,6 +166,8 @@ Ian Bicking
 Ian Lesperance
 Ilya Konstantinov
 Ionuț Turturică
+Isaac Virshup
+Israel Fruchter
 Itxaso Aizpurua
 Iwan Briquemont
 Jaap Broekhuizen
diff --git a/changelog/11367.bugfix.rst b/changelog/11367.bugfix.rst
new file mode 100644
index 00000000000..dda40db0fc9
--- /dev/null
+++ b/changelog/11367.bugfix.rst
@@ -0,0 +1 @@
+Fixed bug where `user_properties` where not being saved in the JUnit XML file if a fixture failed during teardown.
diff --git a/src/_pytest/junitxml.py b/src/_pytest/junitxml.py
index 9242d46d9df..ed259e4c41d 100644
--- a/src/_pytest/junitxml.py
+++ b/src/_pytest/junitxml.py
@@ -502,6 +502,10 @@ def finalize(self, report: TestReport) -> None:
         # Local hack to handle xdist report order.
         workernode = getattr(report, "node", None)
         reporter = self.node_reporters.pop((nodeid, workernode))
+
+        for propname, propvalue in report.user_properties:
+            reporter.add_property(propname, str(propvalue))
+
         if reporter is not None:
             reporter.finalize()
 
@@ -599,9 +603,6 @@ def pytest_runtest_logreport(self, report: TestReport) -> None:
             reporter = self._opentestcase(report)
             reporter.write_captured_output(report)
 
-            for propname, propvalue in report.user_properties:
-                reporter.add_property(propname, str(propvalue))
-
             self.finalize(report)
             report_wid = getattr(report, "worker_id", None)
             report_ii = getattr(report, "item_index", None)
diff --git a/testing/test_junitxml.py b/testing/test_junitxml.py
index 690830329c0..3f88c21e2b7 100644
--- a/testing/test_junitxml.py
+++ b/testing/test_junitxml.py
@@ -1228,6 +1228,36 @@ def test_record(record_property, other):
     result.stdout.fnmatch_lines(["*= 1 passed in *"])
 
 
+def test_record_property_on_test_and_teardown_failure(
+    pytester: Pytester, run_and_parse: RunAndParse
+) -> None:
+    pytester.makepyfile(
+        """
+        import pytest
+
+        @pytest.fixture
+        def other(record_property):
+            record_property("bar", 1)
+            yield
+            assert 0
+
+        def test_record(record_property, other):
+            record_property("foo", "<1")
+            assert 0
+    """
+    )
+    result, dom = run_and_parse()
+    node = dom.find_first_by_tag("testsuite")
+    tnodes = node.find_by_tag("testcase")
+    for tnode in tnodes:
+        psnode = tnode.find_first_by_tag("properties")
+        assert psnode, f"testcase didn't had expected properties:\n{tnode}"
+        pnodes = psnode.find_by_tag("property")
+        pnodes[0].assert_attr(name="bar", value="1")
+        pnodes[1].assert_attr(name="foo", value="<1")
+    result.stdout.fnmatch_lines(["*= 1 failed, 1 error *"])
+
+
 def test_record_property_same_name(
     pytester: Pytester, run_and_parse: RunAndParse
 ) -> None:

From 1de00e9830c57805ec07a0d67095822703b90bb4 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Tue, 5 Sep 2023 23:07:48 +0000
Subject: [PATCH 21/27] [7.4.x] Fix import_path for packages (#11395)

Co-authored-by: Bruno Oliveira <nicoddemus@gmail.com>
---
 changelog/11306.bugfix.rst |  1 +
 src/_pytest/pathlib.py     |  4 ++++
 testing/test_pathlib.py    | 45 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 50 insertions(+)
 create mode 100644 changelog/11306.bugfix.rst

diff --git a/changelog/11306.bugfix.rst b/changelog/11306.bugfix.rst
new file mode 100644
index 00000000000..02e0957a9c6
--- /dev/null
+++ b/changelog/11306.bugfix.rst
@@ -0,0 +1 @@
+Fixed bug using ``--importmode=importlib`` which would cause package ``__init__.py`` files to be imported more than once in some cases.
diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py
index 14fb2e3ae2f..7cf64f03b2c 100644
--- a/src/_pytest/pathlib.py
+++ b/src/_pytest/pathlib.py
@@ -623,6 +623,10 @@ def module_name_from_path(path: Path, root: Path) -> str:
         # Use the parts for the relative path to the root path.
         path_parts = relative_path.parts
 
+    # Module name for packages do not contain the __init__ file.
+    if path_parts[-1] == "__init__":
+        path_parts = path_parts[:-1]
+
     return ".".join(path_parts)
 
 
diff --git a/testing/test_pathlib.py b/testing/test_pathlib.py
index 3d574e85658..1ca6414375e 100644
--- a/testing/test_pathlib.py
+++ b/testing/test_pathlib.py
@@ -18,6 +18,7 @@
 from _pytest.pathlib import get_extended_length_path_str
 from _pytest.pathlib import get_lock_path
 from _pytest.pathlib import import_path
+from _pytest.pathlib import ImportMode
 from _pytest.pathlib import ImportPathMismatchError
 from _pytest.pathlib import insert_missing_modules
 from _pytest.pathlib import maybe_delete_a_numbered_dir
@@ -585,6 +586,10 @@ def test_module_name_from_path(self, tmp_path: Path) -> None:
         result = module_name_from_path(Path("/home/foo/test_foo.py"), Path("/bar"))
         assert result == "home.foo.test_foo"
 
+        # Importing __init__.py files should return the package as module name.
+        result = module_name_from_path(tmp_path / "src/app/__init__.py", tmp_path)
+        assert result == "src.app"
+
     def test_insert_missing_modules(
         self, monkeypatch: MonkeyPatch, tmp_path: Path
     ) -> None:
@@ -615,3 +620,43 @@ def test_parent_contains_child_module_attribute(
         assert sorted(modules) == ["xxx", "xxx.tests", "xxx.tests.foo"]
         assert modules["xxx"].tests is modules["xxx.tests"]
         assert modules["xxx.tests"].foo is modules["xxx.tests.foo"]
+
+    def test_importlib_package(self, monkeypatch: MonkeyPatch, tmp_path: Path):
+        """
+        Importing a package using --importmode=importlib should not import the
+        package's __init__.py file more than once (#11306).
+        """
+        monkeypatch.chdir(tmp_path)
+        monkeypatch.syspath_prepend(tmp_path)
+
+        package_name = "importlib_import_package"
+        tmp_path.joinpath(package_name).mkdir()
+        init = tmp_path.joinpath(f"{package_name}/__init__.py")
+        init.write_text(
+            dedent(
+                """
+                from .singleton import Singleton
+
+                instance = Singleton()
+                """
+            ),
+            encoding="ascii",
+        )
+        singleton = tmp_path.joinpath(f"{package_name}/singleton.py")
+        singleton.write_text(
+            dedent(
+                """
+                class Singleton:
+                    INSTANCES = []
+
+                    def __init__(self) -> None:
+                        self.INSTANCES.append(self)
+                        if len(self.INSTANCES) > 1:
+                            raise RuntimeError("Already initialized")
+                """
+            ),
+            encoding="ascii",
+        )
+
+        mod = import_path(init, root=tmp_path, mode=ImportMode.importlib)
+        assert len(mod.instance.INSTANCES) == 1

From de69883e3a6a923c9eceb28cedf8e9660bd58a51 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Wed, 6 Sep 2023 11:02:29 +0000
Subject: [PATCH 22/27] [7.4.x] improve plugin list disclaimer (#11398)

Co-authored-by: Stefaan Lippens <soxofaan@users.noreply.github.com>
---
 AUTHORS                          |  1 +
 changelog/11391.doc.rst          |  1 +
 doc/en/reference/plugin_list.rst | 22 +++++++++++++++++-----
 scripts/update-plugin-list.py    | 22 +++++++++++++++++-----
 4 files changed, 36 insertions(+), 10 deletions(-)
 create mode 100644 changelog/11391.doc.rst

diff --git a/AUTHORS b/AUTHORS
index d914f3ba906..74043fcfb6c 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -341,6 +341,7 @@ Simon Holesch
 Simon Kerr
 Skylar Downes
 Srinivas Reddy Thatiparthy
+Stefaan Lippens
 Stefan Farmbauer
 Stefan Scherfke
 Stefan Zimmermann
diff --git a/changelog/11391.doc.rst b/changelog/11391.doc.rst
new file mode 100644
index 00000000000..fff324af18d
--- /dev/null
+++ b/changelog/11391.doc.rst
@@ -0,0 +1 @@
+Improved disclaimer on pytest plugin reference page to better indicate this is an automated, non-curated listing.
diff --git a/doc/en/reference/plugin_list.rst b/doc/en/reference/plugin_list.rst
index c882130b03e..42b6a9a8f29 100644
--- a/doc/en/reference/plugin_list.rst
+++ b/doc/en/reference/plugin_list.rst
@@ -1,14 +1,26 @@
 
 .. _plugin-list:
 
-Plugin List
-===========
+Pytest Plugin List
+==================
 
-PyPI projects that match "pytest-\*" are considered plugins and are listed
-automatically together with a manually-maintained list in `the source
-code <https://github.com/pytest-dev/pytest/blob/main/scripts/update-plugin-list.py>`_.
+Below is an automated compilation of ``pytest``` plugins available on `PyPI <https://pypi.org>`_.
+It includes PyPI projects whose names begin with "pytest-" and a handful of manually selected projects.
 Packages classified as inactive are excluded.
 
+For detailed insights into how this list is generated,
+please refer to `the update script <https://github.com/pytest-dev/pytest/blob/main/scripts/update-plugin-list.py>`_.
+
+.. warning::
+
+   Please be aware that this list is not a curated collection of projects
+   and does not undergo a systematic review process.
+   It serves purely as an informational resource to aid in the discovery of ``pytest`` plugins.
+
+   Do not presume any endorsement from the ``pytest`` project or its developers,
+   and always conduct your own quality assessment before incorporating any of these plugins into your own projects.
+
+
 .. The following conditional uses a different format for this list when
    creating a PDF, because otherwise the table gets far too wide for the
    page.
diff --git a/scripts/update-plugin-list.py b/scripts/update-plugin-list.py
index ea7e7986e15..2efe04165c2 100644
--- a/scripts/update-plugin-list.py
+++ b/scripts/update-plugin-list.py
@@ -13,14 +13,26 @@
 FILE_HEAD = r"""
 .. _plugin-list:
 
-Plugin List
-===========
+Pytest Plugin List
+==================
 
-PyPI projects that match "pytest-\*" are considered plugins and are listed
-automatically together with a manually-maintained list in `the source
-code <https://github.com/pytest-dev/pytest/blob/main/scripts/update-plugin-list.py>`_.
+Below is an automated compilation of ``pytest``` plugins available on `PyPI <https://pypi.org>`_.
+It includes PyPI projects whose names begin with "pytest-" and a handful of manually selected projects.
 Packages classified as inactive are excluded.
 
+For detailed insights into how this list is generated,
+please refer to `the update script <https://github.com/pytest-dev/pytest/blob/main/scripts/update-plugin-list.py>`_.
+
+.. warning::
+
+   Please be aware that this list is not a curated collection of projects
+   and does not undergo a systematic review process.
+   It serves purely as an informational resource to aid in the discovery of ``pytest`` plugins.
+
+   Do not presume any endorsement from the ``pytest`` project or its developers,
+   and always conduct your own quality assessment before incorporating any of these plugins into your own projects.
+
+
 .. The following conditional uses a different format for this list when
    creating a PDF, because otherwise the table gets far too wide for the
    page.

From 79c2012d4090bbe0cd0910e1616dc19ca75aea86 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Wed, 6 Sep 2023 13:50:00 +0000
Subject: [PATCH 23/27] [7.4.x] doc: Remove done training (#11400)

Co-authored-by: Florian Bruhin <me@the-compiler.org>
---
 doc/en/index.rst | 1 -
 1 file changed, 1 deletion(-)

diff --git a/doc/en/index.rst b/doc/en/index.rst
index 69ca1dcfea9..bdee8b5dbd9 100644
--- a/doc/en/index.rst
+++ b/doc/en/index.rst
@@ -2,7 +2,6 @@
 
 .. sidebar:: Next Open Trainings
 
-   - `pytest: Professionelles Testen (nicht nur) für Python <https://workshoptage.ch/workshops/2023/pytest-professionelles-testen-nicht-nur-fuer-python-2/>`_, at `Workshoptage 2023 <https://workshoptage.ch/>`_, **September 5th**, `OST <https://www.ost.ch/en>`_ Campus **Rapperswil, Switzerland**
    - `Professional Testing with Python <https://python-academy.com/courses/python_course_testing.html>`_, via `Python Academy <https://www.python-academy.com/>`_, **March 5th to 7th 2024** (3 day in-depth training), **Leipzig, Germany / Remote**
 
    Also see :doc:`previous talks and blogposts <talks>`.

From 6e49a74089540196ae2b2bf8267a530ad9957f3e Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
 <41898282+github-actions[bot]@users.noreply.github.com>
Date: Thu, 7 Sep 2023 13:33:12 +0000
Subject: [PATCH 24/27] [7.4.x] Fix doctest collection of
 `functools.cached_property` objects. (#11403)

Co-authored-by: Ronny Pfannschmidt <opensource@ronnypfannschmidt.de>
---
 AUTHORS                    |  1 +
 changelog/11237.bugfix.rst |  1 +
 src/_pytest/doctest.py     | 20 ++++++++++++++++++++
 testing/test_doctest.py    | 21 +++++++++++++++++++++
 4 files changed, 43 insertions(+)
 create mode 100644 changelog/11237.bugfix.rst

diff --git a/AUTHORS b/AUTHORS
index 74043fcfb6c..e8456d92b31 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -374,6 +374,7 @@ Tony Narlock
 Tor Colvin
 Trevor Bekolay
 Tyler Goodlet
+Tyler Smart
 Tzu-ping Chung
 Vasily Kuznetsov
 Victor Maryama
diff --git a/changelog/11237.bugfix.rst b/changelog/11237.bugfix.rst
new file mode 100644
index 00000000000..d054fc18d1c
--- /dev/null
+++ b/changelog/11237.bugfix.rst
@@ -0,0 +1 @@
+Fix doctest collection of `functools.cached_property` objects.
diff --git a/src/_pytest/doctest.py b/src/_pytest/doctest.py
index 455ad62cc9c..ca41a98ea9c 100644
--- a/src/_pytest/doctest.py
+++ b/src/_pytest/doctest.py
@@ -1,5 +1,6 @@
 """Discover and run doctests in modules and test files."""
 import bdb
+import functools
 import inspect
 import os
 import platform
@@ -536,6 +537,25 @@ def _find(
                         tests, obj, name, module, source_lines, globs, seen
                     )
 
+            if sys.version_info < (3, 13):
+
+                def _from_module(self, module, object):
+                    """`cached_property` objects are never considered a part
+                    of the 'current module'. As such they are skipped by doctest.
+                    Here we override `_from_module` to check the underlying
+                    function instead. https://github.com/python/cpython/issues/107995
+                    """
+                    if hasattr(functools, "cached_property") and isinstance(
+                        object, functools.cached_property
+                    ):
+                        object = object.func
+
+                    # Type ignored because this is a private function.
+                    return super()._from_module(module, object)  # type: ignore[misc]
+
+            else:  # pragma: no cover
+                pass
+
         if self.path.name == "conftest.py":
             module = self.config.pluginmanager._importconftest(
                 self.path,
diff --git a/testing/test_doctest.py b/testing/test_doctest.py
index dfe569987ca..665bdb73b5d 100644
--- a/testing/test_doctest.py
+++ b/testing/test_doctest.py
@@ -482,6 +482,27 @@ def test_doctestmodule(self, pytester: Pytester):
         reprec = pytester.inline_run(p, "--doctest-modules")
         reprec.assertoutcome(failed=1)
 
+    @pytest.mark.skipif(
+        sys.version_info[:2] <= (3, 7), reason="Only Python 3.7 or less"
+    )
+    def test_doctest_cached_property(self, pytester: Pytester):
+        p = pytester.makepyfile(
+            """
+            import functools
+
+            class Foo:
+                @functools.cached_property
+                def foo(self):
+                    '''
+                    >>> assert False, "Tacos!"
+                    '''
+                    ...
+        """
+        )
+        result = pytester.runpytest(p, "--doctest-modules")
+        result.assert_outcomes(failed=1)
+        assert "Tacos!" in result.stdout.str()
+
     def test_doctestmodule_external_and_issue116(self, pytester: Pytester):
         p = pytester.mkpydir("hello")
         p.joinpath("__init__.py").write_text(

From 884b911a9cbf3c97689b473ae7f732fc72e06eea Mon Sep 17 00:00:00 2001
From: Bruno Oliveira <nicoddemus@gmail.com>
Date: Thu, 7 Sep 2023 12:49:25 -0300
Subject: [PATCH 25/27] Fix crash when passing a very long cmdline argument
 (#11404)

Fixes #11394

(cherry picked from commit 28ccf476b91be32ffda303f0d7a8b57e475b465b)
---
 changelog/11394.bugfix.rst |  1 +
 src/_pytest/main.py        |  3 ++-
 src/_pytest/pathlib.py     | 11 +++++++++++
 testing/test_main.py       | 31 +++++++++++++++++++++++++++++++
 testing/test_pathlib.py    | 32 ++++++++++++++++++++++++++++++++
 5 files changed, 77 insertions(+), 1 deletion(-)
 create mode 100644 changelog/11394.bugfix.rst

diff --git a/changelog/11394.bugfix.rst b/changelog/11394.bugfix.rst
new file mode 100644
index 00000000000..aa89c81b01f
--- /dev/null
+++ b/changelog/11394.bugfix.rst
@@ -0,0 +1 @@
+Fixed crash when parsing long command line arguments that might be interpreted as files.
diff --git a/src/_pytest/main.py b/src/_pytest/main.py
index 803b95a2033..ea89a63fa1b 100644
--- a/src/_pytest/main.py
+++ b/src/_pytest/main.py
@@ -36,6 +36,7 @@
 from _pytest.pathlib import absolutepath
 from _pytest.pathlib import bestrelpath
 from _pytest.pathlib import fnmatch_ex
+from _pytest.pathlib import safe_exists
 from _pytest.pathlib import visit
 from _pytest.reports import CollectReport
 from _pytest.reports import TestReport
@@ -895,7 +896,7 @@ def resolve_collection_argument(
         strpath = search_pypath(strpath)
     fspath = invocation_path / strpath
     fspath = absolutepath(fspath)
-    if not fspath.exists():
+    if not safe_exists(fspath):
         msg = (
             "module or package not found: {arg} (missing __init__.py?)"
             if as_pypath
diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py
index 7cf64f03b2c..b5c2d86452f 100644
--- a/src/_pytest/pathlib.py
+++ b/src/_pytest/pathlib.py
@@ -1,5 +1,6 @@
 import atexit
 import contextlib
+import errno
 import fnmatch
 import importlib.util
 import itertools
@@ -791,3 +792,13 @@ def copytree(source: Path, target: Path) -> None:
             shutil.copyfile(x, newx)
         elif x.is_dir():
             newx.mkdir(exist_ok=True)
+
+
+def safe_exists(p: Path) -> bool:
+    """Like Path.exists(), but account for input arguments that might be too long (#11394)."""
+    try:
+        return p.exists()
+    except OSError as e:
+        if e.errno == errno.ENAMETOOLONG:
+            return False
+        raise
diff --git a/testing/test_main.py b/testing/test_main.py
index 71597626790..3c8998c1a35 100644
--- a/testing/test_main.py
+++ b/testing/test_main.py
@@ -262,3 +262,34 @@ def test(fix):
             "* 1 passed in *",
         ]
     )
+
+
+def test_very_long_cmdline_arg(pytester: Pytester) -> None:
+    """
+    Regression test for #11394.
+
+    Note: we could not manage to actually reproduce the error with this code, we suspect
+    GitHub runners are configured to support very long paths, however decided to leave
+    the test in place in case this ever regresses in the future.
+    """
+    pytester.makeconftest(
+        """
+        import pytest
+
+        def pytest_addoption(parser):
+            parser.addoption("--long-list", dest="long_list", action="store", default="all", help="List of things")
+
+        @pytest.fixture(scope="module")
+        def specified_feeds(request):
+            list_string = request.config.getoption("--long-list")
+            return list_string.split(',')
+        """
+    )
+    pytester.makepyfile(
+        """
+        def test_foo(specified_feeds):
+            assert len(specified_feeds) == 100_000
+        """
+    )
+    result = pytester.runpytest("--long-list", ",".join(["helloworld"] * 100_000))
+    result.stdout.fnmatch_lines("* 1 passed *")
diff --git a/testing/test_pathlib.py b/testing/test_pathlib.py
index 1ca6414375e..8a9659aabd9 100644
--- a/testing/test_pathlib.py
+++ b/testing/test_pathlib.py
@@ -1,3 +1,4 @@
+import errno
 import os.path
 import pickle
 import sys
@@ -24,6 +25,7 @@
 from _pytest.pathlib import maybe_delete_a_numbered_dir
 from _pytest.pathlib import module_name_from_path
 from _pytest.pathlib import resolve_package_path
+from _pytest.pathlib import safe_exists
 from _pytest.pathlib import symlink_or_skip
 from _pytest.pathlib import visit
 from _pytest.tmpdir import TempPathFactory
@@ -660,3 +662,33 @@ def __init__(self) -> None:
 
         mod = import_path(init, root=tmp_path, mode=ImportMode.importlib)
         assert len(mod.instance.INSTANCES) == 1
+
+
+def test_safe_exists(tmp_path: Path) -> None:
+    d = tmp_path.joinpath("some_dir")
+    d.mkdir()
+    assert safe_exists(d) is True
+
+    f = tmp_path.joinpath("some_file")
+    f.touch()
+    assert safe_exists(f) is True
+
+    # Use unittest.mock() as a context manager to have a very narrow
+    # patch lifetime.
+    p = tmp_path.joinpath("some long filename" * 100)
+    with unittest.mock.patch.object(
+        Path,
+        "exists",
+        autospec=True,
+        side_effect=OSError(errno.ENAMETOOLONG, "name too long"),
+    ):
+        assert safe_exists(p) is False
+
+    with unittest.mock.patch.object(
+        Path,
+        "exists",
+        autospec=True,
+        side_effect=OSError(errno.EIO, "another kind of error"),
+    ):
+        with pytest.raises(OSError):
+            _ = safe_exists(p)

From 63b0c6f75f218b400a5a42305f9fa3830448f7e8 Mon Sep 17 00:00:00 2001
From: Bruno Oliveira <bruno@soliv.dev>
Date: Thu, 7 Sep 2023 13:15:11 -0300
Subject: [PATCH 26/27] Use _pytest.pathlib.safe_exists in get_dirs_from_args

Related to #11394
---
 src/_pytest/config/__init__.py  | 9 +++------
 src/_pytest/config/findpaths.py | 9 +--------
 src/_pytest/pathlib.py          | 9 ++++-----
 testing/test_pathlib.py         | 5 ++---
 4 files changed, 10 insertions(+), 22 deletions(-)

diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py
index dc2b9f6a160..e3990d175df 100644
--- a/src/_pytest/config/__init__.py
+++ b/src/_pytest/config/__init__.py
@@ -57,6 +57,7 @@
 from _pytest.pathlib import import_path
 from _pytest.pathlib import ImportMode
 from _pytest.pathlib import resolve_package_path
+from _pytest.pathlib import safe_exists
 from _pytest.stash import Stash
 from _pytest.warning_types import PytestConfigWarning
 from _pytest.warning_types import warn_explicit_for
@@ -557,12 +558,8 @@ def _set_initial_conftests(
             anchor = absolutepath(current / path)
 
             # Ensure we do not break if what appears to be an anchor
-            # is in fact a very long option (#10169).
-            try:
-                anchor_exists = anchor.exists()
-            except OSError:  # pragma: no cover
-                anchor_exists = False
-            if anchor_exists:
+            # is in fact a very long option (#10169, #11394).
+            if safe_exists(anchor):
                 self._try_load_conftest(anchor, importmode, rootpath)
                 foundanchor = True
         if not foundanchor:
diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py
index 234b9e12906..02674ffae3b 100644
--- a/src/_pytest/config/findpaths.py
+++ b/src/_pytest/config/findpaths.py
@@ -16,6 +16,7 @@
 from _pytest.outcomes import fail
 from _pytest.pathlib import absolutepath
 from _pytest.pathlib import commonpath
+from _pytest.pathlib import safe_exists
 
 if TYPE_CHECKING:
     from . import Config
@@ -151,14 +152,6 @@ def get_dir_from_path(path: Path) -> Path:
             return path
         return path.parent
 
-    def safe_exists(path: Path) -> bool:
-        # This can throw on paths that contain characters unrepresentable at the OS level,
-        # or with invalid syntax on Windows (https://bugs.python.org/issue35306)
-        try:
-            return path.exists()
-        except OSError:
-            return False
-
     # These look like paths but may not exist
     possible_paths = (
         absolutepath(get_file_part_from_node_id(arg))
diff --git a/src/_pytest/pathlib.py b/src/_pytest/pathlib.py
index b5c2d86452f..5c765c68348 100644
--- a/src/_pytest/pathlib.py
+++ b/src/_pytest/pathlib.py
@@ -1,6 +1,5 @@
 import atexit
 import contextlib
-import errno
 import fnmatch
 import importlib.util
 import itertools
@@ -798,7 +797,7 @@ def safe_exists(p: Path) -> bool:
     """Like Path.exists(), but account for input arguments that might be too long (#11394)."""
     try:
         return p.exists()
-    except OSError as e:
-        if e.errno == errno.ENAMETOOLONG:
-            return False
-        raise
+    except (ValueError, OSError):
+        # ValueError: stat: path too long for Windows
+        # OSError: [WinError 123] The filename, directory name, or volume label syntax is incorrect
+        return False
diff --git a/testing/test_pathlib.py b/testing/test_pathlib.py
index 8a9659aabd9..678fd27feac 100644
--- a/testing/test_pathlib.py
+++ b/testing/test_pathlib.py
@@ -688,7 +688,6 @@ def test_safe_exists(tmp_path: Path) -> None:
         Path,
         "exists",
         autospec=True,
-        side_effect=OSError(errno.EIO, "another kind of error"),
+        side_effect=ValueError("name too long"),
     ):
-        with pytest.raises(OSError):
-            _ = safe_exists(p)
+        assert safe_exists(p) is False

From 45f34dfb8d813b00c7d8060a3ea75f7b4bc5cd7d Mon Sep 17 00:00:00 2001
From: pytest bot <pytestbot@gmail.com>
Date: Thu, 7 Sep 2023 17:21:49 +0000
Subject: [PATCH 27/27] Prepare release version 7.4.2

---
 changelog/11237.bugfix.rst        |  1 -
 changelog/11306.bugfix.rst        |  1 -
 changelog/11367.bugfix.rst        |  1 -
 changelog/11391.doc.rst           |  1 -
 changelog/11394.bugfix.rst        |  1 -
 doc/en/announce/index.rst         |  1 +
 doc/en/announce/release-7.4.2.rst | 18 ++++++++++++++++++
 doc/en/builtin.rst                |  2 +-
 doc/en/changelog.rst              | 25 +++++++++++++++++++++++++
 doc/en/example/reportingdemo.rst  | 20 ++++++++++----------
 doc/en/getting-started.rst        |  2 +-
 11 files changed, 56 insertions(+), 17 deletions(-)
 delete mode 100644 changelog/11237.bugfix.rst
 delete mode 100644 changelog/11306.bugfix.rst
 delete mode 100644 changelog/11367.bugfix.rst
 delete mode 100644 changelog/11391.doc.rst
 delete mode 100644 changelog/11394.bugfix.rst
 create mode 100644 doc/en/announce/release-7.4.2.rst

diff --git a/changelog/11237.bugfix.rst b/changelog/11237.bugfix.rst
deleted file mode 100644
index d054fc18d1c..00000000000
--- a/changelog/11237.bugfix.rst
+++ /dev/null
@@ -1 +0,0 @@
-Fix doctest collection of `functools.cached_property` objects.
diff --git a/changelog/11306.bugfix.rst b/changelog/11306.bugfix.rst
deleted file mode 100644
index 02e0957a9c6..00000000000
--- a/changelog/11306.bugfix.rst
+++ /dev/null
@@ -1 +0,0 @@
-Fixed bug using ``--importmode=importlib`` which would cause package ``__init__.py`` files to be imported more than once in some cases.
diff --git a/changelog/11367.bugfix.rst b/changelog/11367.bugfix.rst
deleted file mode 100644
index dda40db0fc9..00000000000
--- a/changelog/11367.bugfix.rst
+++ /dev/null
@@ -1 +0,0 @@
-Fixed bug where `user_properties` where not being saved in the JUnit XML file if a fixture failed during teardown.
diff --git a/changelog/11391.doc.rst b/changelog/11391.doc.rst
deleted file mode 100644
index fff324af18d..00000000000
--- a/changelog/11391.doc.rst
+++ /dev/null
@@ -1 +0,0 @@
-Improved disclaimer on pytest plugin reference page to better indicate this is an automated, non-curated listing.
diff --git a/changelog/11394.bugfix.rst b/changelog/11394.bugfix.rst
deleted file mode 100644
index aa89c81b01f..00000000000
--- a/changelog/11394.bugfix.rst
+++ /dev/null
@@ -1 +0,0 @@
-Fixed crash when parsing long command line arguments that might be interpreted as files.
diff --git a/doc/en/announce/index.rst b/doc/en/announce/index.rst
index 85dfa0894fe..39fdfc13776 100644
--- a/doc/en/announce/index.rst
+++ b/doc/en/announce/index.rst
@@ -6,6 +6,7 @@ Release announcements
    :maxdepth: 2
 
 
+   release-7.4.2
    release-7.4.1
    release-7.4.0
    release-7.3.2
diff --git a/doc/en/announce/release-7.4.2.rst b/doc/en/announce/release-7.4.2.rst
new file mode 100644
index 00000000000..22191e7b4f9
--- /dev/null
+++ b/doc/en/announce/release-7.4.2.rst
@@ -0,0 +1,18 @@
+pytest-7.4.2
+=======================================
+
+pytest 7.4.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/builtin.rst b/doc/en/builtin.rst
index 0d673d0426e..405289444a8 100644
--- a/doc/en/builtin.rst
+++ b/doc/en/builtin.rst
@@ -105,7 +105,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:757
         Fixture that returns a :py:class:`dict` that will be injected into the
         namespace of doctests.
 
diff --git a/doc/en/changelog.rst b/doc/en/changelog.rst
index be7e7fabaef..ecfeeb662b6 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.2 (2023-09-07)
+=========================
+
+Bug Fixes
+---------
+
+- `#11237 <https://github.com/pytest-dev/pytest/issues/11237>`_: Fix doctest collection of `functools.cached_property` objects.
+
+
+- `#11306 <https://github.com/pytest-dev/pytest/issues/11306>`_: Fixed bug using ``--importmode=importlib`` which would cause package ``__init__.py`` files to be imported more than once in some cases.
+
+
+- `#11367 <https://github.com/pytest-dev/pytest/issues/11367>`_: Fixed bug where `user_properties` where not being saved in the JUnit XML file if a fixture failed during teardown.
+
+
+- `#11394 <https://github.com/pytest-dev/pytest/issues/11394>`_: Fixed crash when parsing long command line arguments that might be interpreted as files.
+
+
+
+Improved Documentation
+----------------------
+
+- `#11391 <https://github.com/pytest-dev/pytest/issues/11391>`_: Improved disclaimer on pytest plugin reference page to better indicate this is an automated, non-curated listing.
+
+
 pytest 7.4.1 (2023-09-02)
 =========================
 
diff --git a/doc/en/example/reportingdemo.rst b/doc/en/example/reportingdemo.rst
index d4d3d3ce202..cb59c4b42e1 100644
--- a/doc/en/example/reportingdemo.rst
+++ b/doc/en/example/reportingdemo.rst
@@ -554,13 +554,13 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     E       AssertionError: assert False
     E        +  where False = <built-in method startswith of str object at 0xdeadbeef0027>('456')
     E        +    where <built-in method startswith of str object at 0xdeadbeef0027> = '123'.startswith
-    E        +      where '123' = <function TestMoreErrors.test_startswith_nested.<locals>.f at 0xdeadbeef0006>()
-    E        +    and   '456' = <function TestMoreErrors.test_startswith_nested.<locals>.g at 0xdeadbeef0029>()
+    E        +      where '123' = <function TestMoreErrors.test_startswith_nested.<locals>.f at 0xdeadbeef0029>()
+    E        +    and   '456' = <function TestMoreErrors.test_startswith_nested.<locals>.g at 0xdeadbeef002a>()
 
     failure_demo.py:235: AssertionError
     _____________________ TestMoreErrors.test_global_func ______________________
 
-    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002a>
+    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002b>
 
         def test_global_func(self):
     >       assert isinstance(globf(42), float)
@@ -571,18 +571,18 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     failure_demo.py:238: AssertionError
     _______________________ TestMoreErrors.test_instance _______________________
 
-    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002b>
+    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002c>
 
         def test_instance(self):
             self.x = 6 * 7
     >       assert self.x != 42
     E       assert 42 != 42
-    E        +  where 42 = <failure_demo.TestMoreErrors object at 0xdeadbeef002b>.x
+    E        +  where 42 = <failure_demo.TestMoreErrors object at 0xdeadbeef002c>.x
 
     failure_demo.py:242: AssertionError
     _______________________ TestMoreErrors.test_compare ________________________
 
-    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002c>
+    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002d>
 
         def test_compare(self):
     >       assert globf(10) < 5
@@ -592,7 +592,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     failure_demo.py:245: AssertionError
     _____________________ TestMoreErrors.test_try_finally ______________________
 
-    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002d>
+    self = <failure_demo.TestMoreErrors object at 0xdeadbeef002e>
 
         def test_try_finally(self):
             x = 1
@@ -603,7 +603,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     failure_demo.py:250: AssertionError
     ___________________ TestCustomAssertMsg.test_single_line ___________________
 
-    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef002e>
+    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef002f>
 
         def test_single_line(self):
             class A:
@@ -618,7 +618,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     failure_demo.py:261: AssertionError
     ____________________ TestCustomAssertMsg.test_multiline ____________________
 
-    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef002f>
+    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef0030>
 
         def test_multiline(self):
             class A:
@@ -637,7 +637,7 @@ Here is a nice run of several failures and how ``pytest`` presents things:
     failure_demo.py:268: AssertionError
     ___________________ TestCustomAssertMsg.test_custom_repr ___________________
 
-    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef0030>
+    self = <failure_demo.TestCustomAssertMsg object at 0xdeadbeef0031>
 
         def test_custom_repr(self):
             class JSON:
diff --git a/doc/en/getting-started.rst b/doc/en/getting-started.rst
index 31cfa68bf38..e426e0c5072 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.1
+    pytest 7.4.2
 
 .. _`simpletest`: