| 372 | |
| 373 | |
| 374 | def test_used_password(pgconn, dsn, monkeypatch): |
| 375 | assert isinstance(pgconn.used_password, bool) |
| 376 | |
| 377 | # Assume that if a password was passed then it was needed. |
| 378 | # Note that the server may still need a password passed via pgpass |
| 379 | # so it may be that has_password is false but still a password was |
| 380 | # requested by the server and passed by libpq. |
| 381 | info = pq.Conninfo.parse(dsn.encode()) |
| 382 | |
| 383 | if "PGPASSWORD" in os.environ: |
| 384 | assert pgconn.used_password |
| 385 | if [i for i in info if i.keyword == b"password"][0].val is not None: |
| 386 | assert pgconn.used_password |
| 387 | |
| 388 | pgconn.finish() |
| 389 | pgconn.used_password |
| 390 | |
| 391 | |
| 392 | @pytest.mark.libpq(">= 16") |