Skip to content

Commit

Permalink
reuse result by configuring it at setUp()
Browse files Browse the repository at this point in the history
Checklist:
- Invoke tearDown even if the test method fails
- Run multiple tests ✅

---

Output:
➜ python3 src/test_case_test.py
5 run, 0 failed
  • Loading branch information
kaiosilveira committed Mar 19, 2023
1 parent 69640ad commit 2ca814b
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/test_case_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@


class TestCaseTest(TestCase):
def setUp(self) -> None:
self.result = TestResult()

def testTemplateMethod(self) -> None:
test = WasRun("testMethod")
result = TestResult()
test.run(result)
assert ("1 run, 0 failed" == result.summary())
test.run(self.result)
assert ("1 run, 0 failed" == self.result.summary())

def testFailedResult(self) -> None:
test = WasRun("testBrokenMethod")
result = TestResult()
test.run(result)
assert ("1 run, 1 failed" == result.summary())
test.run(self.result)
assert ("1 run, 1 failed" == self.result.summary())

def testFailedResultFormatting(self) -> None:
result = TestResult()
Expand All @@ -26,17 +27,15 @@ def testFailedResultFormatting(self) -> None:

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

def testSuite(self) -> None:
suite = TestSuite()
suite.add(WasRun("testMethod"))
suite.add(WasRun("testBrokenMethod"))
result = TestResult()
suite.run(result)
assert ("2 run, 1 failed" == result.summary())
suite.run(self.result)
assert ("2 run, 1 failed" == self.result.summary())


suite = TestSuite()
Expand Down

0 comments on commit 2ca814b

Please sign in to comment.