Skip to content

Commit 8502a12

Browse files
committed
Replace psycopg2, psycopg2cffi -> psycopg in testing and docs
Now that we only support Django>=4.2, can switch our testing and docs to the newer library, and drop the PyPy compat hacks. Note this does not affect psycopg2 support for users of the library in any way.
1 parent 52b2205 commit 8502a12

File tree

5 files changed

+5
-28
lines changed

5 files changed

+5
-28
lines changed

docs/database.rst

+4-8
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,12 @@ Put this into ``conftest.py``::
325325
import pytest
326326
from django.db import connections
327327

328-
import psycopg2
329-
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
328+
import psycopg
330329

331330

332331
def run_sql(sql):
333-
conn = psycopg2.connect(database='postgres')
334-
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
335-
cur = conn.cursor()
336-
cur.execute(sql)
337-
conn.close()
332+
with psycopg.connect(database='postgres') as conn:
333+
conn.execute(sql)
338334

339335

340336
@pytest.fixture(scope='session')
@@ -505,7 +501,7 @@ Put this in ``conftest.py``::
505501

506502
.. warning::
507503
This snippet shows ``cursor().executescript()`` which is `sqlite` specific, for
508-
other database engines this method might differ. For instance, psycopg2 uses
504+
other database engines this method might differ. For instance, psycopg uses
509505
``cursor().execute()``.
510506

511507

pyproject.toml

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ files = [
9090
module = [
9191
"django.*",
9292
"configurations.*",
93-
"psycopg2cffi.*",
9493
]
9594
ignore_missing_imports = true
9695

pytest_django_test/settings_postgres.py

-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@
33
from .settings_base import * # noqa: F403
44

55

6-
# PyPy compatibility
7-
try:
8-
from psycopg2cffi import compat
9-
10-
compat.register()
11-
except ImportError:
12-
pass
13-
14-
156
DATABASES = {
167
"default": {
178
"ENGINE": "django.db.backends.postgresql",

tests/conftest.py

-8
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ def django_pytester(
7474
"""
7575
import django
7676
77-
# Pypy compatibility
78-
try:
79-
from psycopg2cffi import compat
80-
except ImportError:
81-
pass
82-
else:
83-
compat.register()
84-
8577
DATABASES = %(db_settings)s
8678
DATABASE_ROUTERS = ['pytest_django_test.db_router.DbRouter']
8779

tox.ini

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ deps =
1818
mysql_myisam: mysqlclient==2.1.0
1919
mysql_innodb: mysqlclient==2.1.0
2020

21-
!pypy3-postgres: psycopg2-binary
22-
pypy3-postgres: psycopg2cffi
21+
postgres: psycopg[binary]
2322
coverage: coverage[toml]
2423
coverage: coverage-enable-subprocess
2524

0 commit comments

Comments
 (0)