tests: Fix test compatibility with Python 3.14 forkserver Python 3.14 changed the default multiprocessing start method on Linux from "fork" to "forkserver". The test_forall_all_projects_called_once test uses mock.patch.object on Project.GetRevisionId, but class-level mock patches do not survive into forkserver worker processes because they start from a clean Python interpreter rather than inheriting the parent's memory. Replace the mock with setting revisionId directly on each Project instance so GetRevisionId() short-circuits without touching git. This works with any multiprocessing start method since the string attribute is part of the Project objects stored in _parallel_context, which is properly serialized to workers via initargs. Bug: 425319437 Change-Id: Icd3bbd010921d7652bb2425fad85974df9198367 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/602941 Tested-by: Brian Gan <brgan@google.com> Commit-Queue: Brian Gan <brgan@google.com> Reviewed-by: Gavin Mak <gavinmak@google.com>
diff --git a/tests/test_subcmds_forall.py b/tests/test_subcmds_forall.py index e36c8b6..67ec43c 100644 --- a/tests/test_subcmds_forall.py +++ b/tests/test_subcmds_forall.py
@@ -17,12 +17,10 @@ import contextlib import io from pathlib import Path -from unittest import mock import utils_for_test import manifest_xml -import project import subcmds @@ -87,13 +85,16 @@ opts, args = cmd.OptionParser.parse_args(["-c", "echo $REPO_PROJECT"]) opts.verbose = False + # Set revisionId directly so GetRevisionId() short-circuits without + # touching git. Using mock.patch.object on the class does not work + # with Python 3.14+, which defaults to "forkserver" on Linux — + # class-level patches do not survive into forkserver worker processes. + for proj in manifest.projects: + proj.revisionId = "refs/heads/main" + with contextlib.redirect_stdout(io.StringIO()) as stdout: - # Mock to not have the Execute fail on remote check. - with mock.patch.object( - project.Project, "GetRevisionId", return_value="refs/heads/main" - ): - # Run the forall command. - cmd.Execute(opts, args) + # Run the forall command. + cmd.Execute(opts, args) output = stdout.getvalue() # Verify that we got every project name in the output.