From afa985c135957cae6ebed01748e5f4fcc18ba975 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 22 Mar 2019 17:16:08 +0100 Subject: [PATCH] Revisit coverage in some tests --- testing/test_compat.py | 21 +++++++++++++-------- testing/test_modimport.py | 11 ++++++----- testing/test_session.py | 6 ++---- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/testing/test_compat.py b/testing/test_compat.py index 79224deef..6c4d24398 100644 --- a/testing/test_compat.py +++ b/testing/test_compat.py @@ -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 \n" + "stopped at " + ), + ): + 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 diff --git a/testing/test_modimport.py b/testing/test_modimport.py index cb5f5ccd3..33862799b 100644 --- a/testing/test_modimport.py +++ b/testing/test_modimport.py @@ -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, + ) diff --git a/testing/test_session.py b/testing/test_session.py index e5eb081d4..20079cd1b 100644 --- a/testing/test_session.py +++ b/testing/test_session.py @@ -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