summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-01-31 08:16:50 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-01-31 09:20:49 -0500
commit716b31214126c4a06d8262a62153e5d1fa45fa54 (patch)
tree799b71514cf978927aa8f7144cda8ede25655c2a
parent6e93714d655c87e62cd03a4ff3e1739245b684b9 (diff)
downloadpython-coveragepy-git-716b31214126c4a06d8262a62153e5d1fa45fa54.tar.gz
test: adapt to pytest assertion messages
Bare "assert" statements don't produce the same assertion message as self.assertEqual did: they don't include the two values compared. For some of our own asserts, add back the detailed message. For some checks of asserts, it's fine that the values are missing because the longer messsage includes the information.
-rw-r--r--tests/coveragetest.py8
-rw-r--r--tests/test_testing.py12
2 files changed, 10 insertions, 10 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index ed3f1839..2e6f1323 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -198,7 +198,7 @@ class CoverageTest(
if isinstance(lines[0], int):
# lines is just a list of numbers, it must match the statements
# found in the code.
- assert statements == lines
+ assert statements == lines, "{!r} != {!r}".format(statements, lines)
else:
# lines is a list of possible line number lists, one of them
# must match.
@@ -210,7 +210,7 @@ class CoverageTest(
missing_formatted = analysis.missing_formatted()
if isinstance(missing, string_class):
- assert missing_formatted == missing
+ assert missing_formatted == missing, "{!r} != {!r}".format(missing_formatted, missing)
else:
for missing_list in missing:
if missing_formatted == missing_list:
@@ -244,7 +244,7 @@ class CoverageTest(
frep = StringIO()
cov.report(mod, file=frep, show_missing=True)
rep = " ".join(frep.getvalue().split("\n")[2].split()[1:])
- assert report == rep
+ assert report == rep, "{!r} != {!r}".format(report, rep)
return cov
@@ -351,7 +351,7 @@ class CoverageTest(
"""
ret_actual = command_line(args)
- assert ret_actual == ret
+ assert ret_actual == ret, "{!r} != {!r}".format(ret_actual, ret)
# Some distros rename the coverage command, and need a way to indicate
# their new command name to the tests. This is here for them to override,
diff --git a/tests/test_testing.py b/tests/test_testing.py
index 52560a5f..21e09dcc 100644
--- a/tests/test_testing.py
+++ b/tests/test_testing.py
@@ -48,10 +48,10 @@ class CoverageTestTest(CoverageTest):
self.make_file("whoville.txt", "We are here!")
self.assert_exists("whoville.txt")
self.assert_doesnt_exist("shadow.txt")
- msg = "False is not true : File 'whoville.txt' shouldn't exist"
+ msg = "File 'whoville.txt' shouldn't exist"
with pytest.raises(AssertionError, match=msg):
self.assert_doesnt_exist("whoville.txt")
- msg = "False is not true : File 'shadow.txt' should exist"
+ msg = "File 'shadow.txt' should exist"
with pytest.raises(AssertionError, match=msg):
self.assert_exists("shadow.txt")
@@ -64,25 +64,25 @@ class CoverageTestTest(CoverageTest):
self.assert_file_count("afile.*", 1)
self.assert_file_count("*.q", 0)
msg = re.escape(
- "3 != 13 : There should be 13 files matching 'a*.txt', but there are these: "
+ "There should be 13 files matching 'a*.txt', but there are these: "
"['abcde.txt', 'afile.txt', 'axczz.txt']"
)
with pytest.raises(AssertionError, match=msg):
self.assert_file_count("a*.txt", 13)
msg = re.escape(
- "2 != 12 : There should be 12 files matching '*c*.txt', but there are these: "
+ "There should be 12 files matching '*c*.txt', but there are these: "
"['abcde.txt', 'axczz.txt']"
)
with pytest.raises(AssertionError, match=msg):
self.assert_file_count("*c*.txt", 12)
msg = re.escape(
- "1 != 11 : There should be 11 files matching 'afile.*', but there are these: "
+ "There should be 11 files matching 'afile.*', but there are these: "
"['afile.txt']"
)
with pytest.raises(AssertionError, match=msg):
self.assert_file_count("afile.*", 11)
msg = re.escape(
- "0 != 10 : There should be 10 files matching '*.q', but there are these: []"
+ "There should be 10 files matching '*.q', but there are these: []"
)
with pytest.raises(AssertionError, match=msg):
self.assert_file_count("*.q", 10)