From 03222a5aac3096d8ef1f4cff3d98ce560d0b58aa Mon Sep 17 00:00:00 2001 From: kazk Date: Thu, 9 May 2019 11:29:00 -0700 Subject: [PATCH] Show warnings by default --- codewars_unittest/test_runner.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/codewars_unittest/test_runner.py b/codewars_unittest/test_runner.py index e47c71b..59906a6 100644 --- a/codewars_unittest/test_runner.py +++ b/codewars_unittest/test_runner.py @@ -1,5 +1,6 @@ import sys import unittest +import warnings from itertools import groupby # Use timeit.default_timer for Python 2 compatibility. @@ -10,18 +11,33 @@ class CodewarsTestRunner(object): - def __init__(self, stream=None, group_by_module=False): + def __init__(self, stream=None, group_by_module=False, warnings=None): if stream is None: stream = sys.stdout self.stream = _WritelnDecorator(stream) self.group_by_module = group_by_module self.results = [] + if warnings is None and not sys.warnoptions: + self.warnings = "default" + else: + # Set to given `warnings` or use `None` to respect values passed to `-W` + self.warnings = warnings def run(self, test): - if isinstance(test, unittest.TestSuite): - self._run_modules(_to_tree(_flatten(test))) - else: - self._run_case(test) + with warnings.catch_warnings(): + if self.warnings: + warnings.simplefilter(self.warnings) + # Minimize noise from deprecated assertion methods + if self.warnings in ["default", "always"]: + warnings.filterwarnings( + "module", + category=DeprecationWarning, + message=r"Please use assert\w+ instead.", + ) + if isinstance(test, unittest.TestSuite): + self._run_modules(_to_tree(_flatten(test))) + else: + self._run_case(test) return self._make_result() def _make_result(self):