Skip to content

Commit 5a6cc27

Browse files
authored
Show warnings by default (#4)
Show warnings by default
2 parents 1cfaf74 + 03222a5 commit 5a6cc27

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

codewars_unittest/test_runner.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import unittest
3+
import warnings
34
from itertools import groupby
45

56
# Use timeit.default_timer for Python 2 compatibility.
@@ -10,18 +11,33 @@
1011

1112

1213
class CodewarsTestRunner(object):
13-
def __init__(self, stream=None, group_by_module=False):
14+
def __init__(self, stream=None, group_by_module=False, warnings=None):
1415
if stream is None:
1516
stream = sys.stdout
1617
self.stream = _WritelnDecorator(stream)
1718
self.group_by_module = group_by_module
1819
self.results = []
20+
if warnings is None and not sys.warnoptions:
21+
self.warnings = "default"
22+
else:
23+
# Set to given `warnings` or use `None` to respect values passed to `-W`
24+
self.warnings = warnings
1925

2026
def run(self, test):
21-
if isinstance(test, unittest.TestSuite):
22-
self._run_modules(_to_tree(_flatten(test)))
23-
else:
24-
self._run_case(test)
27+
with warnings.catch_warnings():
28+
if self.warnings:
29+
warnings.simplefilter(self.warnings)
30+
# Minimize noise from deprecated assertion methods
31+
if self.warnings in ["default", "always"]:
32+
warnings.filterwarnings(
33+
"module",
34+
category=DeprecationWarning,
35+
message=r"Please use assert\w+ instead.",
36+
)
37+
if isinstance(test, unittest.TestSuite):
38+
self._run_modules(_to_tree(_flatten(test)))
39+
else:
40+
self._run_case(test)
2541
return self._make_result()
2642

2743
def _make_result(self):

0 commit comments

Comments
 (0)