diff --git a/repo_trace.py b/repo_trace.py index ee224ea7c..d8ed58329 100644 --- a/repo_trace.py +++ b/repo_trace.py @@ -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): diff --git a/tests/conftest.py b/tests/conftest.py index ce3c3d6ce..c76046806 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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") diff --git a/tests/test_repo_trace.py b/tests/test_repo_trace.py index 3ec540b25..7b938a6f6 100644 --- a/tests/test_repo_trace.py +++ b/tests/test_repo_trace.py @@ -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)