diff --git a/patacrep/utils.py b/patacrep/utils.py index e3c18db9..998fe738 100644 --- a/patacrep/utils.py +++ b/patacrep/utils.py @@ -1,8 +1,5 @@ """Some utility functions""" -import contextlib -import logging - from collections import UserDict class DictOfDict(UserDict): @@ -78,13 +75,3 @@ def yesno(string): string, ", ".join(["'{}'".format(string) for string in yes_strings + no_strings]), )) - -@contextlib.contextmanager -def logging_reduced(module_name, tmp_level=logging.CRITICAL): - """Temporarly reduce the logging level of a specific module - """ - logger = logging.getLogger(module_name) - old_level = logger.getEffectiveLevel() - logger.setLevel(tmp_level) - yield - logger.setLevel(old_level) diff --git a/test/__init__.py b/test/__init__.py index aa4a5a18..41fb4a66 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -9,11 +9,20 @@ import unittest import patacrep @contextlib.contextmanager -def disable_logging(): - """Context locally disabling logging.""" - logging.disable(logging.CRITICAL) - yield - logging.disable(logging.NOTSET) +def logging_reduced(module_name=None, tmp_level=logging.CRITICAL): + """Temporarly reduce the logging level of a specific module + or globally if None + """ + if module_name: + logger = logging.getLogger(module_name) + old_level = logger.getEffectiveLevel() + logger.setLevel(tmp_level) + yield + logger.setLevel(old_level) + else: + logging.disable(logging.CRITICAL) + yield + logging.disable(logging.NOTSET) def suite(): """Return a :class:`TestSuite` object, testing all module :mod:`patacrep`. diff --git a/test/test_content/test_content.py b/test/test_content/test_content.py index 7532450e..5857506c 100644 --- a/test/test_content/test_content.py +++ b/test/test_content/test_content.py @@ -10,8 +10,8 @@ import json from patacrep.songs import DataSubpath, DEFAULT_CONFIG from patacrep import content, files from patacrep.content import song, section, songsection, tex -from patacrep.utils import logging_reduced +from .. import logging_reduced from .. import dynamic # pylint: disable=unused-import class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): diff --git a/test/test_song/test_parser.py b/test/test_song/test_parser.py index ae122bdd..0ea602a2 100644 --- a/test/test_song/test_parser.py +++ b/test/test_song/test_parser.py @@ -12,7 +12,7 @@ from patacrep import files from patacrep.songs import DEFAULT_CONFIG from patacrep.encoding import open_read -from .. import disable_logging +from .. import logging_reduced from .. import dynamic # pylint: disable=unused-import OUTPUTS = { @@ -59,7 +59,7 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): destname = "{}.{}".format(base, out_format) with self.chdir(): with open_read(destname) as expectfile: - with disable_logging(): + with logging_reduced(): song = self.song_plugins[out_format][in_format](sourcename, self.config) expected = expectfile.read().strip().replace( "@TEST_FOLDER@",