Skip to content

Commit 2df9d05

Browse files
authored
Merge pull request #4982 from blueyed/cover
Revisit coverage in some tests
2 parents 4142c41 + afa985c commit 2df9d05

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

testing/test_compat.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919
def test_is_generator():
2020
def zap():
21-
yield
21+
yield # pragma: no cover
2222

2323
def foo():
24-
pass
24+
pass # pragma: no cover
2525

2626
assert is_generator(zap)
2727
assert not is_generator(foo)
@@ -37,15 +37,20 @@ def __repr__(self):
3737

3838
def __getattr__(self, attr):
3939
if not self.left:
40-
raise RuntimeError("its over")
40+
raise RuntimeError("it's over") # pragma: no cover
4141
self.left -= 1
4242
return self
4343

4444
evil = Evil()
4545

46-
with pytest.raises(ValueError):
47-
res = get_real_func(evil)
48-
print(res)
46+
with pytest.raises(
47+
ValueError,
48+
match=(
49+
"could not find real function of <Evil left=800>\n"
50+
"stopped at <Evil left=800>"
51+
),
52+
):
53+
get_real_func(evil)
4954

5055

5156
def test_get_real_func():
@@ -54,14 +59,14 @@ def test_get_real_func():
5459
def decorator(f):
5560
@wraps(f)
5661
def inner():
57-
pass
62+
pass # pragma: no cover
5863

5964
if six.PY2:
6065
inner.__wrapped__ = f
6166
return inner
6267

6368
def func():
64-
pass
69+
pass # pragma: no cover
6570

6671
wrapped_func = decorator(decorator(func))
6772
assert get_real_func(wrapped_func) is func

testing/test_modimport.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ def test_fileimport(modfile):
3030
stderr=subprocess.PIPE,
3131
)
3232
(out, err) = p.communicate()
33-
if p.returncode != 0:
34-
pytest.fail(
35-
"importing %s failed (exitcode %d): out=%r, err=%r"
36-
% (modfile, p.returncode, out, err)
37-
)
33+
assert p.returncode == 0, "importing %s failed (exitcode %d): out=%r, err=%r" % (
34+
modfile,
35+
p.returncode,
36+
out,
37+
err,
38+
)

testing/test_session.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ def test_raises_doesnt():
6868
passed, skipped, failed = reprec.listoutcomes()
6969
assert len(failed) == 1
7070
out = failed[0].longrepr.reprcrash.message
71-
if not out.find("DID NOT RAISE") != -1:
72-
print(out)
73-
pytest.fail("incorrect raises() output")
71+
assert "DID NOT RAISE" in out
7472

7573
def test_syntax_error_module(self, testdir):
7674
reprec = testdir.inline_runsource("this is really not python")
@@ -148,7 +146,7 @@ def test_one(): pass
148146
)
149147
try:
150148
reprec = testdir.inline_run(testdir.tmpdir)
151-
except pytest.skip.Exception:
149+
except pytest.skip.Exception: # pragma: no covers
152150
pytest.fail("wrong skipped caught")
153151
reports = reprec.getreports("pytest_collectreport")
154152
assert len(reports) == 1

0 commit comments

Comments
 (0)