summaryrefslogtreecommitdiff
path: root/tests/test_testing.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-01-07 20:07:04 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-01-07 20:07:04 -0500
commitb7035114aa515d9d1fe171a9bf678868e76d8f74 (patch)
tree60609f38079b9de18cdbee1d255e96e9c666dd31 /tests/test_testing.py
parentd1c92d8e6b066a7b16d625b566853821afe8b46c (diff)
parentd93ddb9524a3e3535541812bbeade8e8ff822409 (diff)
downloadpython-coveragepy-git-b7035114aa515d9d1fe171a9bf678868e76d8f74.tar.gz
Branch analysis is now done with AST instead of bytecode
Diffstat (limited to 'tests/test_testing.py')
-rw-r--r--tests/test_testing.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/tests/test_testing.py b/tests/test_testing.py
index 9fc7f11d..1dafdd0d 100644
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -6,13 +6,15 @@
import datetime
import os
+import re
import sys
+import textwrap
import coverage
from coverage.backunittest import TestCase
from coverage.backward import to_bytes
from coverage.files import actual_path
-from coverage.test_helpers import EnvironmentAwareMixin, TempDirMixin
+from coverage.test_helpers import EnvironmentAwareMixin, TempDirMixin, DelayedAssertionMixin
from tests.coveragetest import CoverageTest
@@ -97,6 +99,45 @@ class EnvironmentAwareMixinTest(EnvironmentAwareMixin, TestCase):
self.assertNotIn("XYZZY_PLUGH", os.environ)
+class DelayedAssertionMixinTest(DelayedAssertionMixin, TestCase):
+ """Test the `delayed_assertions` method."""
+
+ def test_delayed_assertions(self):
+ # Two assertions can be shown at once:
+ msg = re.escape(textwrap.dedent("""\
+ 2 failed assertions:
+ 'x' != 'y'
+ - x
+ + y
+
+ 'w' != 'z'
+ - w
+ + z
+ """))
+ with self.assertRaisesRegex(AssertionError, msg):
+ with self.delayed_assertions():
+ self.assertEqual("x", "y")
+ self.assertEqual("w", "z")
+
+ # It's also OK if only one fails:
+ msg = re.escape(textwrap.dedent("""\
+ 'w' != 'z'
+ - w
+ + z
+ """))
+ with self.assertRaisesRegex(AssertionError, msg):
+ with self.delayed_assertions():
+ self.assertEqual("x", "x")
+ self.assertEqual("w", "z")
+
+ # If an error happens, it gets reported immediately, no special
+ # handling:
+ with self.assertRaises(ZeroDivisionError):
+ with self.delayed_assertions():
+ self.assertEqual("x", "y")
+ self.assertEqual("w", 1/0)
+
+
class CoverageTestTest(CoverageTest):
"""Test the methods in `CoverageTest`."""