diff --git a/tests/run_tests.py b/tests/run_tests.py index ea7956df..89d46d80 100644 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -4,6 +4,7 @@ import dataclasses import asyncio import re +import pytest import aiosql from utils import log @@ -303,7 +304,7 @@ def run_date_time(conn, queries, db): elif _DB[db] in ("mysql", "mariadb"): now = queries.misc.my_get_now_date_time(conn) else: - assert False, f"unexpected driver: {db}" + pytest.fail(f"unexpected driver: {db}") assert re.match(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$", now) @@ -323,17 +324,17 @@ def run_object_attributes(conn, queries, db): elif isinstance(r, dict): assert r["name"] == calvin.name and r["age"] == calvin.age else: - assert False, "unexpected query output" + pytest.fail("unexpected query output") # failures try: queries.misc.person_attributes(conn, q=calvin) - assert False, "should fail on missing parameter p" + pytest.fail("should fail on missing parameter p") except ValueError as e: assert "missing named parameter p" in str(e) del calvin.age try: queries.misc.person_attributes(conn, p=calvin) - assert False, "should fail on missing attribute age" + pytest.fail("should fail on missing attribute age") except ValueError as e: assert "parameter p is missing attribute age" in str(e) diff --git a/tests/test_asyncpg.py b/tests/test_asyncpg.py index 10b5ba96..70d9d845 100644 --- a/tests/test_asyncpg.py +++ b/tests/test_asyncpg.py @@ -163,6 +163,6 @@ def test_maybe_order_params(): a = aiosql.adapters.asyncpg.AsyncPGAdapter() try: a.maybe_order_params("foo", "wrong-type-parameter") - assert False, "exception should be raised" # pragma: no cover + pytest.fail("exception should be raised") # pragma: no cover except ValueError as e: assert "dict or tuple" in str(e) diff --git a/tests/test_loading.py b/tests/test_loading.py index ca33e01a..a46bff92 100644 --- a/tests/test_loading.py +++ b/tests/test_loading.py @@ -137,7 +137,7 @@ def test_loading_query_signature_with_duplicate_parameter(): def test_adapters(): try: aiosql.aiosql._make_driver_adapter("no-such-driver-adapter") - assert False, "must raise an exception" # pragma: no cover + pytest.fail("must raise an exception") # pragma: no cover except ValueError as e: assert "unregistered driver_adapter" in str(e) @@ -158,13 +158,13 @@ class NoSuchConnector: try: aiosql.aiosql._make_driver_adapter(NoSuchConnector) - assert False, "must raise an exception" # pragma: no cover + pytest.fail("must raise an exception") # pragma: no cover except ValueError as e: assert "Unexpected driver_adapter" in str(e) try: aiosql.aiosql._make_driver_adapter(True) # type: ignore - assert False, "must raise an exception" # pragma: no cover + pytest.fail("must raise an exception") # pragma: no cover except ValueError as e: assert "Unexpected driver_adapter" in str(e) @@ -172,7 +172,7 @@ class NoSuchConnector: def test_no_such_path(): try: aiosql.from_path("/no/such/file", "sqlite3") - assert False, "must raise an exception" # pragma: no cover + pytest.fail("must raise an exception") # pragma: no cover except SQLLoadException as e: assert "File does not exist" in str(e) @@ -186,18 +186,18 @@ def test_misc(sql_file): try: queries = aiosql.queries.Queries("sqlite3") queries._make_sync_fn(("hello", None, -1, "SELECT NULL;", None, None, None, None)) - assert False, "must raise an exception" # pragma: no cover + pytest.fail("must raise an exception") # pragma: no cover except ValueError as e: assert "Unknown operation_type" in str(e) try: db = aiosql.from_str("-- name: a*b\nSELECT 'ab'\n", "sqlite3") - assert False, "must raise en exception" # pragma: no cover + pytest.fail("must raise en exception") # pragma: no cover except Exception as e: assert "invalid query name and operation" in str(e) ql = aiosql.query_loader.QueryLoader(None, None) try: ql.load_query_data_from_dir_path(sql_file) - assert False, "must raise en exception" # pragma: no cover + pytest.fail("must raise en exception") # pragma: no cover except ValueError as e: assert "must be a directory" in str(e) @@ -211,7 +211,7 @@ def test_kwargs(): assert 42 == queries.plus_one(conn, val=41) try: queries.plus_one(conn, 2) - assert False, "must raise an exception" # pragma: no cover + pytest.fail("must raise an exception") # pragma: no cover except ValueError as e: assert "kwargs" in str(e) # kwargs_only == False @@ -221,6 +221,6 @@ def test_kwargs(): assert 42 == queries.plus_two(conn, val=40) try: queries.plus_two(conn, 2, val=41) - assert False, "must raise an exception" # pragma: no cover + pytest.fail("must raise an exception") # pragma: no cover except ValueError as e: assert "mix" in str(e)