diff --git a/HISTORY.rst b/HISTORY.rst index 92b4e48ee5..84e6918fac 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -26,6 +26,8 @@ * Update Pillow to version 6.0.0 * Update PyYAML to version 5.1. Update use of safe_load and safe_dump to load and dump using the SafeLoader. +* Add SilenceLoggerTestCaseMixin to lower level of loggers + during tests. 3.1.11 (2019-04-XX) =================== diff --git a/docs/releases/3.2.rst b/docs/releases/3.2.rst index e24e607ebe..2cb50f40a9 100644 --- a/docs/releases/3.2.rst +++ b/docs/releases/3.2.rst @@ -50,6 +50,8 @@ Other changes to the API app's URLs module. * Update PyYAML to version 5.1. Update use of safe_load and safe_dump to load and dump using the CSafeLoader and SafeLoader as fallback. +* Add SilenceLoggerTestCaseMixin to lower level of loggers + during tests. Removals -------- diff --git a/mayan/apps/common/tests/base.py b/mayan/apps/common/tests/base.py index 5cdd423e23..ecf9ac2b17 100644 --- a/mayan/apps/common/tests/base.py +++ b/mayan/apps/common/tests/base.py @@ -12,12 +12,12 @@ from mayan.apps.user_management.tests.mixins import UserTestCaseMixin from .mixins import ( ClientMethodsTestCaseMixin, ContentTypeCheckTestCaseMixin, DatabaseConversionMixin, OpenFileCheckTestCaseMixin, - RandomPrimaryKeyModelMonkeyPatchMixin, TempfileCheckTestCasekMixin, - TestViewTestCaseMixin + RandomPrimaryKeyModelMonkeyPatchMixin, SilenceLoggerTestCaseMixin, + TempfileCheckTestCasekMixin, TestViewTestCaseMixin ) -class BaseTestCase(RandomPrimaryKeyModelMonkeyPatchMixin, DatabaseConversionMixin, ACLTestCaseMixin, OpenFileCheckTestCaseMixin, TempfileCheckTestCasekMixin, TestCase): +class BaseTestCase(SilenceLoggerTestCaseMixin, RandomPrimaryKeyModelMonkeyPatchMixin, DatabaseConversionMixin, ACLTestCaseMixin, OpenFileCheckTestCaseMixin, TempfileCheckTestCasekMixin, TestCase): """ This is the most basic test case class any test in the project should use. """ diff --git a/mayan/apps/common/tests/mixins.py b/mayan/apps/common/tests/mixins.py index 41d386fd86..f28dd1df85 100644 --- a/mayan/apps/common/tests/mixins.py +++ b/mayan/apps/common/tests/mixins.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import glob import importlib +import logging import os import random @@ -209,6 +210,23 @@ class RandomPrimaryKeyModelMonkeyPatchMixin(object): super(RandomPrimaryKeyModelMonkeyPatchMixin, self).tearDown() +class SilenceLoggerTestCaseMixin(object): + test_case_logger = None + + def tearDown(self): + if self.test_case_logger: + self.test_case_logger.setLevel(level=self.test_case_logger_level) + + super(SilenceLoggerTestCaseMixin, self).tearDown() + + def _silence_logger(self, name): + self.test_case_logger = logging.getLogger(name=name) + self.test_case_logger_level = self.test_case_logger.level + self.test_case_logger.setLevel( + level=logging.CRITICAL + ) + + class TempfileCheckTestCasekMixin(object): # Ignore the jvmstat instrumentation and GitLab's CI .config files # Ignore LibreOffice fontconfig cache dir diff --git a/mayan/apps/converter/tests/test_transformations.py b/mayan/apps/converter/tests/test_transformations.py index 0541708aba..cde27af70e 100644 --- a/mayan/apps/converter/tests/test_transformations.py +++ b/mayan/apps/converter/tests/test_transformations.py @@ -112,6 +112,8 @@ class TransformationBaseTestCase(TestCase): class TransformationTestCase(GenericDocumentTestCase): def test_crop_transformation_optional_arguments(self): + self._silence_logger(name='mayan.apps.converter.managers') + document_page = self.document.pages.first() Transformation.objects.add_for_model( @@ -122,6 +124,8 @@ class TransformationTestCase(GenericDocumentTestCase): self.assertTrue(document_page.generate_image().startswith('page')) def test_crop_transformation_invalid_arguments(self): + self._silence_logger(name='mayan.apps.converter.managers') + document_page = self.document.pages.first() Transformation.objects.add_for_model( @@ -132,6 +136,8 @@ class TransformationTestCase(GenericDocumentTestCase): self.assertTrue(document_page.generate_image().startswith('page')) def test_crop_transformation_non_valid_range_arguments(self): + self._silence_logger(name='mayan.apps.converter.managers') + document_page = self.document.pages.first() Transformation.objects.add_for_model( @@ -142,6 +148,8 @@ class TransformationTestCase(GenericDocumentTestCase): self.assertTrue(document_page.generate_image().startswith('page')) def test_crop_transformation_overlapping_ranges_arguments(self): + self._silence_logger(name='mayan.apps.converter.managers') + document_page = self.document.pages.first() Transformation.objects.add_for_model(