Skip to content

Commit

Permalink
Replace psycopg2, psycopg2cffi -> psycopg in testing and docs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bluetech committed Sep 2, 2024
1 parent 52b2205 commit 8502a12
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 28 deletions.
12 changes: 4 additions & 8 deletions docs/database.rst
Original file line number Diff line number Diff line change
Expand Up @@ -325,16 +325,12 @@ Put this into ``conftest.py``::
import pytest
from django.db import connections

import psycopg2
from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
import psycopg


def run_sql(sql):
conn = psycopg2.connect(database='postgres')
conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
cur = conn.cursor()
cur.execute(sql)
conn.close()
with psycopg.connect(database='postgres') as conn:
conn.execute(sql)


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

.. warning::
This snippet shows ``cursor().executescript()`` which is `sqlite` specific, for
other database engines this method might differ. For instance, psycopg2 uses
other database engines this method might differ. For instance, psycopg uses
``cursor().execute()``.


Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ files = [
module = [
"django.*",
"configurations.*",
"psycopg2cffi.*",
]
ignore_missing_imports = true

Expand Down
9 changes: 0 additions & 9 deletions pytest_django_test/settings_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
from .settings_base import * # noqa: F403


# PyPy compatibility
try:
from psycopg2cffi import compat

compat.register()
except ImportError:
pass


DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
Expand Down
8 changes: 0 additions & 8 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ def django_pytester(
"""
import django
# Pypy compatibility
try:
from psycopg2cffi import compat
except ImportError:
pass
else:
compat.register()
DATABASES = %(db_settings)s
DATABASE_ROUTERS = ['pytest_django_test.db_router.DbRouter']
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ deps =
mysql_myisam: mysqlclient==2.1.0
mysql_innodb: mysqlclient==2.1.0

!pypy3-postgres: psycopg2-binary
pypy3-postgres: psycopg2cffi
postgres: psycopg[binary]
coverage: coverage[toml]
coverage: coverage-enable-subprocess

Expand Down

0 comments on commit 8502a12

Please sign in to comment.