From f085e01717c752f1d9d39ec1be0d3c29ec9346fb Mon Sep 17 00:00:00 2001 From: Ivan Shcheklein Date: Sun, 17 Mar 2019 19:33:09 -0700 Subject: [PATCH] try to fix progess bar test in a parallel pytest environment --- dvc/progress.py | 6 ++++++ tests/unit/test_progress.py | 5 ++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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()