From: btharper Date: Sun, 6 Oct 2019 04:00:24 +0000 (-0400) Subject: Eliminate dead code by using pytests.raises instead of try/except/else X-Git-Tag: 2.11.0~54^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F1071%2Fhead;p=thirdparty%2Fjinja.git Eliminate dead code by using pytests.raises instead of try/except/else --- diff --git a/tests/test_api.py b/tests/test_api.py index 343d1de6..e37d5cfc 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -223,12 +223,8 @@ class TestUndefined(object): pytest.raises(UndefinedError, t.render, test=test) def test_undefined_and_special_attributes(self): - try: + with pytest.raises(AttributeError): Undefined('Foo').__dict__ - except AttributeError: - pass - else: - assert False, "Expected actual attribute error" def test_logging_undefined(self): _messages = [] diff --git a/tests/test_security.py b/tests/test_security.py index 5c8639c4..6b2743fc 100644 --- a/tests/test_security.py +++ b/tests/test_security.py @@ -140,12 +140,8 @@ class TestSandbox(object): assert t.render(ctx) == rv env.intercepted_binops = frozenset(['+']) t = env.from_string('{{ %s }}' % expr) - try: + with pytest.raises(TemplateRuntimeError): t.render(ctx) - except TemplateRuntimeError as e: - pass - else: - assert False, 'expected runtime error' def test_unary_operator_intercepting(self, env): def disable_op(arg): @@ -157,12 +153,8 @@ class TestSandbox(object): assert t.render(ctx) == rv env.intercepted_unops = frozenset(['-']) t = env.from_string('{{ %s }}' % expr) - try: + with pytest.raises(TemplateRuntimeError): t.render(ctx) - except TemplateRuntimeError as e: - pass - else: - assert False, 'expected runtime error' @pytest.mark.sandbox