1010import configparser as _configparser
1111import dataclasses as _dataclasses
1212import json as _json
13+ import os
1314import pathlib as _pathlib
1415import shutil as _shutil
1516import subprocess as _subprocess
@@ -189,6 +190,11 @@ def initialize_git_submodules() -> bool:
189190 Returns:
190191 Whether any git submodules were initialized.
191192 """
193+ if is_golden_testing ():
194+ # We don't use external tools when running tests because they are too flaky, as
195+ # different versions emit different outputs
196+ return False
197+
192198 gitmodules_path = _pathlib .Path (".gitmodules" )
193199
194200 if not gitmodules_path .exists ():
@@ -287,8 +293,14 @@ def initialize_git_repo() -> bool:
287293 Returns:
288294 Whether the project was initialized as a git repository.
289295 """
296+ if is_golden_testing ():
297+ # We don't use external tools when running tests because they are too flaky, as
298+ # different versions emit different outputs
299+ return False
300+
290301 if _pathlib .Path (".git" ).exists ():
291302 return False
303+
292304 print ()
293305 note ("Initializing git repository..." )
294306 try_run (
@@ -309,6 +321,11 @@ def commit_git_changes(*, first_commit: bool) -> None:
309321 Args:
310322 first_commit: Whether this is the first commit in the git repository.
311323 """
324+ if is_golden_testing ():
325+ # We don't use external tools when running tests because they are too flaky, as
326+ # different versions emit different outputs
327+ return
328+
312329 if not try_run (["git" , "status" , "--porcelain" ]):
313330 return
314331
@@ -367,6 +384,11 @@ def is_file_empty(path: _pathlib.Path) -> bool:
367384
368385def print_generated_tree () -> None :
369386 """Print the generated files tree."""
387+ if is_golden_testing ():
388+ # We don't use external tools when running tests because they are too flaky, as
389+ # different versions emit different outputs
390+ return
391+
370392 result = try_run (["tree" ])
371393 if result is not None and result .returncode == 0 :
372394 print ()
@@ -487,6 +509,8 @@ def try_run(
487509 note_on_failure: If not `None`, print this note if the command fails (either
488510 because of an error or a non-zero status code).
489511 verbose: Whether to print the command before running it.
512+ shell: Whether to run the command in a shell. If `True`, `cmd` must be a
513+ string, otherwise it must be a list of strings.
490514
491515 Returns:
492516 The result of the command or `None` if the command could not be run because
@@ -513,6 +537,15 @@ def try_run(
513537 return result
514538
515539
540+ def is_golden_testing () -> bool :
541+ """Return `True` if we are running as part of a golden testing.
542+
543+ Returns:
544+ Whether we are running as part of a golden testing.
545+ """
546+ return os .environ .get ("GOLDEN_TEST" , None ) is not None
547+
548+
516549def recursive_overwrite_move (src : _pathlib .Path , dst : _pathlib .Path ) -> None :
517550 """Recursively move a directory overwriting the target files if they exist.
518551
0 commit comments