Skip to content

Commit

Permalink
wrapper around TestProgram to catch SystemExit
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris NeJame committed Jun 22, 2017
1 parent 52ca76e commit 72796b2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
9 changes: 6 additions & 3 deletions contextional/tests/test_failure.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

import unittest

from contextional.tests.tools import SilentTestRunner
from contextional.tests.tools import (
SilentTestRunner,
TestingTestProgram,
)
from contextional.tests.failure import expected_stream_output


class TestFailureResult(unittest.TestCase):

@classmethod
def setUpClass(cls):
test_program = unittest.main(
test_program = TestingTestProgram(
module="contextional.tests.failure",
testRunner=SilentTestRunner,
argv=["contextional/tests/test_failure.py"],
exit=False,
# exit=False,
)
cls.test_results = test_program.result
cls.stream_output = cls.test_results.test_run_output
Expand Down
20 changes: 13 additions & 7 deletions contextional/tests/test_success.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@

import unittest

from contextional.tests.tools import SilentTestRunner
from contextional.tests.tools import (
SilentTestRunner,
TestingTestProgram,
)
from contextional.tests.success import expected_stream_output


class TestSuccessResult(unittest.TestCase):

@classmethod
def setUpClass(cls):
test_program = unittest.main(
module="contextional.tests.success",
testRunner=SilentTestRunner,
argv=["contextional/tests/test_success.py"],
exit=False,
)
try:
test_program = TestingTestProgram(
module="contextional.tests.success",
testRunner=SilentTestRunner,
argv=["contextional/tests/test_success.py"],
# exit=False,
)
except SystemExit:
pass
cls.test_results = test_program.result
cls.stream_output = cls.test_results.test_run_output

Expand Down
10 changes: 10 additions & 0 deletions contextional/tests/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from unittest import (
_TextTestResult,
TextTestRunner,
TestProgram,
)


Expand Down Expand Up @@ -32,3 +33,12 @@ def __init__(self, *args, **kwargs):
kwargs["verbosity"] = 2
kwargs["resultclass"] = TextTestResultHolder
super(SilentTestRunner, self).__init__(*args, **kwargs)


class TestingTestProgram(TestProgram):

def runTests(self):
try:
super(TestingTestProgram, self).runTests()
except SystemExit:
pass

0 comments on commit 72796b2

Please sign in to comment.