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 test_is_generator():
def zap(): def zap():
yield yield # pragma: no cover
def foo(): def foo():
pass pass # pragma: no cover
assert is_generator(zap) assert is_generator(zap)
assert not is_generator(foo) assert not is_generator(foo)
@ -37,15 +37,20 @@ def test_real_func_loop_limit():
def __getattr__(self, attr): def __getattr__(self, attr):
if not self.left: if not self.left:
raise RuntimeError("its over") raise RuntimeError("it's over") # pragma: no cover
self.left -= 1 self.left -= 1
return self return self
evil = Evil() evil = Evil()
with pytest.raises(ValueError): with pytest.raises(
res = get_real_func(evil) ValueError,
print(res) 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(): def test_get_real_func():
@ -54,14 +59,14 @@ def test_get_real_func():
def decorator(f): def decorator(f):
@wraps(f) @wraps(f)
def inner(): def inner():
pass pass # pragma: no cover
if six.PY2: if six.PY2:
inner.__wrapped__ = f inner.__wrapped__ = f
return inner return inner
def func(): def func():
pass pass # pragma: no cover
wrapped_func = decorator(decorator(func)) wrapped_func = decorator(decorator(func))
assert get_real_func(wrapped_func) is func assert get_real_func(wrapped_func) is func

View File

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

View File

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