]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Catch only expected exception in test_psycopg_dbapi20.py::test_connect_args()
authorDenis Laxalde <denis.laxalde@dalibo.com>
Tue, 2 Nov 2021 10:44:23 +0000 (11:44 +0100)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Wed, 3 Nov 2021 15:54:40 +0000 (16:54 +0100)
tests/test_psycopg_dbapi20.py

index 1e0f03f235f0b7cae2292b6728ce78867684a4be..dbf6670ceab87761ebe40d9bd49f88251f234d6b 100644 (file)
@@ -134,18 +134,17 @@ def test_connect_args(monkeypatch, pgconn, args, kwargs, want):
 
 
 @pytest.mark.parametrize(
-    "args, kwargs",
+    "args, kwargs, exctype",
     [
-        (("host=foo", "host=bar"), {}),
-        (("", ""), {}),
-        ((), {"nosuchparam": 42}),
+        (("host=foo", "host=bar"), {}, TypeError),
+        (("", ""), {}, TypeError),
+        ((), {"nosuchparam": 42}, psycopg.ProgrammingError),
     ],
 )
-def test_connect_badargs(monkeypatch, pgconn, args, kwargs):
+def test_connect_badargs(monkeypatch, pgconn, args, kwargs, exctype):
     def fake_connect(conninfo):
         return pgconn
         yield
 
-    monkeypatch.setattr(psycopg.connection, "connect", fake_connect)
-    with pytest.raises((TypeError, psycopg.ProgrammingError)):
+    with pytest.raises(exctype):
         psycopg.connect(*args, **kwargs)