Skip to content
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

Report failed tests #10

Merged
merged 6 commits into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
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
16 changes: 13 additions & 3 deletions src/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ def setUp(self) -> None:
def run(self) -> None:
result = TestResult()
result.testStarted()
self.setUp()
method = getattr(self, self.name)
method()

try:
self.setUp()
except:
result.testFailed()
return result

try:
method = getattr(self, self.name)
method()
except:
result.testFailed()

self.tearDown()
return result

Expand Down
21 changes: 21 additions & 0 deletions src/test_case_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
from test_case import TestCase
from was_run import WasRun
from test_result import TestResult


class TestCaseTestWithBrokenSetup(TestCase):
def __init__(self, name) -> None:
TestCase.__init__(self, name)

def setUp(self) -> None:
raise Exception

def testFailedSetUp(self) -> None:
result = self.run()
assert ("1 run, 1 failed" == result.summary())


class TestCaseTest(TestCase):
Expand All @@ -13,6 +26,14 @@ def testFailedResult(self) -> None:
result = test.run()
assert ("1 run, 1 failed" == result.summary())

def testFailedResultFormatting(self) -> None:
result = TestResult()
result.testStarted()
result.testFailed()
assert ("1 run, 1 failed" == result.summary())


TestCaseTest("testTemplateMethod").run()
TestCaseTest("testFailedResultFormatting").run()
TestCaseTest("testFailedResult").run()
TestCaseTestWithBrokenSetup("testFailedSetUp").run()
6 changes: 5 additions & 1 deletion src/test_result.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
class TestResult:
def __init__(self) -> None:
self.runCount = 0
self.errorCount = 0

def testStarted(self) -> None:
self.runCount = self.runCount + 1

def testFailed(self) -> None:
self.errorCount = self.errorCount + 1

def summary(self):
return "%d run, 0 failed" % self.runCount
return "%d run, %d failed" % (self.runCount, self.errorCount)