mirror of
https://gerrit.googlesource.com/git-repo
synced 2026-09-26 08:41:54 +00:00
Fix fail in test_repo_trace if trace is disabled
If env has REPO_TRACE 0, then the test produces: FileNotFoundError: No such file or directory: TRACE_FILE_from_test' because it assumes trace is always enabled. Improve by enabling trace for this test class. Also modify the repo_trace.SetTrace API to take an optional True/False if needed, still defaults to True though. Change-Id: I2bb4632eb45ee529fc1785833e0bafd9c36f0875 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/445541 Commit-Queue: Fredrik de Groot <fredrik.de.groot@haleytek.com> Reviewed-by: Mike Frysinger <vapier@google.com> Reviewed-by: Brian Gan <brgan@google.com> Tested-by: Fredrik de Groot <fredrik.de.groot@haleytek.com>
This commit is contained in:
committed by
gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com
parent
8c7e0a683e
commit
e7d4d97ffc
+3
-3
@@ -57,10 +57,10 @@ def SetTraceToStderr():
|
||||
_TRACE_TO_STDERR = True
|
||||
|
||||
|
||||
def SetTrace():
|
||||
"""Enables tracing."""
|
||||
def SetTrace(value: bool = True) -> None:
|
||||
"""Enables by default, or disables tracing."""
|
||||
global _TRACE
|
||||
_TRACE = True
|
||||
_TRACE = value
|
||||
|
||||
|
||||
def _SetTraceFile(quiet):
|
||||
|
||||
@@ -26,6 +26,7 @@ import repo_trace
|
||||
@pytest.fixture(autouse=True)
|
||||
def disable_repo_trace(tmp_path):
|
||||
"""Set an environment marker to relax certain strict checks for test code.""" # noqa: E501
|
||||
repo_trace.SetTrace(False)
|
||||
repo_trace._TRACE_FILE = str(tmp_path / "TRACE_FILE_from_test")
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,9 @@ def test_trace_max_size_enforced(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
"""Check Trace behavior."""
|
||||
content = "git chicken"
|
||||
|
||||
# Enable trace for the test, in case users have it disabled.
|
||||
monkeypatch.setattr(repo_trace, "_TRACE", True)
|
||||
|
||||
with repo_trace.Trace(content, first_trace=True):
|
||||
pass
|
||||
first_trace_size = os.path.getsize(repo_trace._TRACE_FILE)
|
||||
|
||||
Reference in New Issue
Block a user