Revisit coverage in some tests

This commit is contained in:
Daniel Hahler 2019-03-22 17:16:08 +01:00
parent 15d608867d
commit afa985c135
3 changed files with 21 additions and 17 deletions

View File

@ -18,10 +18,10 @@ from _pytest.outcomes import OutcomeException
def test_is_generator():
def zap():
yield
yield # pragma: no cover
def foo():
pass
pass # pragma: no cover
assert is_generator(zap)
assert not is_generator(foo)
@ -37,15 +37,20 @@ def test_real_func_loop_limit():
def __getattr__(self, attr):
if not self.left:
raise RuntimeError("its over")
raise RuntimeError("it's over") # pragma: no cover
self.left -= 1
return self
evil = Evil()
with pytest.raises(ValueError):
res = get_real_func(evil)
print(res)
with pytest.raises(
ValueError,
match=(
"could not find real function of <Evil left=800>\n"
"stopped at <Evil left=800>"
),
):
get_real_func(evil)
def test_get_real_func():
@ -54,14 +59,14 @@ def test_get_real_func():
def decorator(f):
@wraps(f)
def inner():
pass
pass # pragma: no cover
if six.PY2:
inner.__wrapped__ = f
return inner
def func():
pass
pass # pragma: no cover
wrapped_func = decorator(decorator(func))
assert get_real_func(wrapped_func) is func

View File

@ -30,8 +30,9 @@ def test_fileimport(modfile):
stderr=subprocess.PIPE,
)
(out, err) = p.communicate()
if p.returncode != 0:
pytest.fail(
"importing %s failed (exitcode %d): out=%r, err=%r"
% (modfile, p.returncode, out, err)
assert p.returncode == 0, "importing %s failed (exitcode %d): out=%r, err=%r" % (
modfile,
p.returncode,
out,
err,
)

View File

@ -68,9 +68,7 @@ class SessionTests(object):
passed, skipped, failed = reprec.listoutcomes()
assert len(failed) == 1
out = failed[0].longrepr.reprcrash.message
if not out.find("DID NOT RAISE") != -1:
print(out)
pytest.fail("incorrect raises() output")
assert "DID NOT RAISE" in out
def test_syntax_error_module(self, testdir):
reprec = testdir.inline_runsource("this is really not python")
@ -148,7 +146,7 @@ class SessionTests(object):
)
try:
reprec = testdir.inline_run(testdir.tmpdir)
except pytest.skip.Exception:
except pytest.skip.Exception: # pragma: no covers
pytest.fail("wrong skipped caught")
reports = reprec.getreports("pytest_collectreport")
assert len(reports) == 1