Skip to content

Show warnings by default #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions codewars_unittest/test_runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import sys
import unittest
import warnings
from itertools import groupby

# Use timeit.default_timer for Python 2 compatibility.
Expand All @@ -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):
Expand Down