From cdf318fff77e81cc260660ba694c0576b23032ff Mon Sep 17 00:00:00 2001 From: Alexander Schepanovski Date: Tue, 30 Apr 2019 17:43:39 +0700 Subject: [PATCH] test: abandon default DEBUG log level in tests Now simple `py.test` command won't use DEBUG log level and `py.test ... --log-level=LEVEL` will do what it's supposed to. Staging continues to use DEBUG log level. This is part of #1888 resolution. --- tests/__main__.py | 4 ++-- tests/basic_env.py | 1 - tests/conftest.py | 12 ++++++++++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/__main__.py b/tests/__main__.py index a14479097..9cf04d8ff 100644 --- a/tests/__main__.py +++ b/tests/__main__.py @@ -18,7 +18,7 @@ else: params = " ".join(sys.argv[1:]) cmd = ( - "py.test -v -n=4 --timeout=600 --timeout_method=thread --cov=dvc " - "{params} ".format(params=params) + "py.test -v -n=4 --timeout=600 --timeout_method=thread --log-level=debug" + " --cov=dvc {params} ".format(params=params) ) check_call(cmd, shell=True) diff --git a/tests/basic_env.py b/tests/basic_env.py index 831875b50..9b05cb649 100644 --- a/tests/basic_env.py +++ b/tests/basic_env.py @@ -163,7 +163,6 @@ class TestDvcFixture(TestGitFixture): super(TestDvcFixture, self).setUp() self.dvc = DvcRepo.init(self._root_dir) self.dvc.scm.commit("init dvc") - logger.setLevel("DEBUG") def tearDown(self): self.dvc.scm.git.close() diff --git a/tests/conftest.py b/tests/conftest.py index c73c2f099..c5a7b076b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,8 +11,16 @@ from .basic_env import TestDirFixture @pytest.fixture(autouse=True) -def debug(caplog): - with caplog.at_level("DEBUG", logger="dvc"): +def reset_loglevel(request, caplog): + """ + Use it to ensure log level at the start of each test + regardless of dvc.logger.setup(), Repo configs or whatever. + """ + level = request.config.getoption("--log-level") + if level: + with caplog.at_level(level.upper(), logger="dvc"): + yield + else: yield