diff --git a/dvc/progress.py b/dvc/progress.py index 05315f8f7..6245c14de 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -38,6 +38,12 @@ class Progress(object): self._print(line, end="") sys.stdout.flush() + def reset(self): + with self._lock: + self._n_total = 0 + self._n_finished = 0 + self._line = None + def refresh(self, line=None): """Refreshes progress bar.""" # Just go away if it is locked. Will update next time diff --git a/tests/unit/test_progress.py b/tests/unit/test_progress.py index 3a2974147..94e40d79b 100644 --- a/tests/unit/test_progress.py +++ b/tests/unit/test_progress.py @@ -7,7 +7,10 @@ from dvc.progress import progress, progress_aware class TestProgressAware(TestCase): @mock.patch("sys.stdout.isatty", return_value=True) @mock.patch("dvc.progress.Progress._print") - def test(self, mock_print, mock_isatty): + def test(self, mock_print, _): + # progress is a global object, can be shared between tests when + # run in multi-threading environment with pytest + progress.reset() function = progress_aware(lambda: None) function()