From d2a1ba4de6d8f8e66545a4222ec6360e80733e3e Mon Sep 17 00:00:00 2001 From: James Turton Date: Thu, 31 Mar 2022 12:11:21 +0200 Subject: [PATCH] Use idiomatic pytest to test for a raised exception. --- tests/unit_tests/db_engine_specs/test_drill.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/unit_tests/db_engine_specs/test_drill.py b/tests/unit_tests/db_engine_specs/test_drill.py index 493a8bdc843da..ad7254870f6ef 100644 --- a/tests/unit_tests/db_engine_specs/test_drill.py +++ b/tests/unit_tests/db_engine_specs/test_drill.py @@ -17,7 +17,7 @@ # pylint: disable=unused-argument, import-outside-toplevel, protected-access from flask.ctx import AppContext -from superset.db_engine_specs.exceptions import SupersetDBAPIProgrammingError +from pytest import raises def test_odbc_impersonation(app_context: AppContext) -> None: @@ -78,14 +78,10 @@ def test_invalid_impersonation(app_context: AppContext) -> None: from sqlalchemy.engine.url import URL from superset.db_engine_specs.drill import DrillEngineSpec + from superset.db_engine_specs.exceptions import SupersetDBAPIProgrammingError url = URL("drill+foobar") username = "DoAsUser" - exception_type = None - try: + with raises(SupersetDBAPIProgrammingError): DrillEngineSpec.modify_url_for_impersonation(url, True, username) - except Exception as e: - exception_type = type(e) - - assert exception_type == SupersetDBAPIProgrammingError