summaryrefslogtreecommitdiff
path: root/tools/test_util.py
diff options
context:
space:
mode:
authorAndy Hayden <andyhayden1@gmail.com>2019-06-08 04:46:57 -0700
committerRyan Dahl <ry@tinyclouds.org>2019-06-08 07:46:57 -0400
commit5960e398ecab914effec821cc6da5f3a091fdb50 (patch)
treebb12c155ef59b725dcc0d7a32b757e47718cdaa1 /tools/test_util.py
parent4ea2df6759abf3a99e07fe720987805075c8a18b (diff)
make tests quieter (#2468)
Don't mix every http request in with the tests output. Don't print that the file servers are starting unless -vv flag is passed. Capture the output of run with run_output which returns stdout, stderr and exit_code. Test against this rather than relying on sys.exit.
Diffstat (limited to 'tools/test_util.py')
-rw-r--r--tools/test_util.py34
1 files changed, 17 insertions, 17 deletions
diff --git a/tools/test_util.py b/tools/test_util.py
index cec181ac0..6540f37aa 100644
--- a/tools/test_util.py
+++ b/tools/test_util.py
@@ -3,12 +3,13 @@
# Runs the full test suite.
# Usage: ./tools/test.py out/Debug
import argparse
+import contextlib
import os
import sys
import unittest
from util import (enable_ansi_colors, build_path, RESET, FG_RED, FG_GREEN,
- executable_suffix, run, run_output, rmtree, tests_path)
+ executable_suffix, rmtree, tests_path)
class DenoTestCase(unittest.TestCase):
@@ -22,6 +23,14 @@ class DenoTestCase(unittest.TestCase):
# overload the test result class
class ColorTextTestResult(unittest.TextTestResult):
+ @contextlib.contextmanager
+ def color(self, code):
+ self.stream.write(code)
+ try:
+ yield
+ finally:
+ self.stream.write(RESET)
+
def getDescription(self, test):
name = str(test)
if name.startswith("test_"):
@@ -29,25 +38,16 @@ class ColorTextTestResult(unittest.TextTestResult):
return name
def addSuccess(self, test):
- if self.showAll:
- self.stream.write(FG_GREEN)
- super(ColorTextTestResult, self).addSuccess(test)
- if self.showAll:
- self.stream.write(RESET)
+ with self.color(FG_GREEN):
+ super(ColorTextTestResult, self).addSuccess(test)
def addError(self, test, err):
- if self.showAll:
- self.stream.write(FG_RED)
- super(ColorTextTestResult, self).addError(test, err)
- if self.showAll:
- self.stream.write(RESET)
+ with self.color(FG_RED):
+ super(ColorTextTestResult, self).addError(test, err)
def addFailure(self, test, err):
- if self.showAll:
- self.stream.write(FG_RED)
- super(ColorTextTestResult, self).addFailure(test, err)
- if self.showAll:
- self.stream.write(RESET)
+ with self.color(FG_RED):
+ super(ColorTextTestResult, self).addFailure(test, err)
class ColorTextTestRunner(unittest.TextTestRunner):
@@ -133,7 +133,7 @@ def run_tests(test_cases=None):
suite = unittest.TestSuite(filtered_tests)
runner = ColorTextTestRunner(
- verbosity=args.verbose + 1, failfast=args.failfast)
+ verbosity=args.verbose + 2, failfast=args.failfast)
result = runner.run(suite)
if not result.wasSuccessful():