From 051b5217bf39e3d9ac8184204214106998c6ae52 Mon Sep 17 00:00:00 2001 From: btharper Date: Sun, 6 Oct 2019 00:00:24 -0400 Subject: [PATCH] Eliminate dead code by using pytests.raises instead of try/except/else --- tests/test_api.py | 6 +----- tests/test_security.py | 12 ++---------- 2 files changed, 3 insertions(+), 15 deletions(-) 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 -- 2.47.2