Skip to content

Commit

Permalink
Stop testing against PostgreSQL
Browse files Browse the repository at this point in the history
factory_boy never interacts with the database directly; all access is
mediated through mature ORMs (Django, SQLAlchemy).

Any difference in behaviour regarding the databases would have to be
handled by those ORMs, not on our level.

This reduces the size of the test matrix, and simplifies the test setup
code.

See: #1077
  • Loading branch information
rbarrois committed Aug 18, 2024
1 parent da7554c commit 35e4f9d
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 111 deletions.
11 changes: 0 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@ jobs:
- "3.12"
- "pypy-3.9"
- "pypy-3.10"
database-type:
- "sqlite"
- "postgres"

services:
postgresdb:
image: postgres:alpine
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: password

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -405,11 +405,9 @@ To test with a specific framework version, you may use a ``tox`` target:
# run tests inside a specific environment (django)
$ tox -e py310-djangomain
$ tox -e py310-djangomain-postgres
# run tests inside a specific environment (alchemy)
$ tox -e py310-alchemy
$ tox -e py310-alchemy-postgres
# run tests inside a specific environment (mongoengine)
$ tox -e py310-mongo
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ dev =
mypy
Pillow
SQLAlchemy
sqlalchemy_utils
mongoengine
mongomock
wheel>=0.32.0
Expand Down
25 changes: 1 addition & 24 deletions tests/alchemyapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,11 @@


"""Helpers for testing SQLAlchemy apps."""
import os

from sqlalchemy import Column, Integer, Unicode, create_engine
from sqlalchemy.orm import declarative_base, scoped_session, sessionmaker

try:
import psycopg2 # noqa: F401
USING_POSTGRES = True
except ImportError:
try:
# pypy does not support `psycopg2` or `psycopg2-binary`
# This is a package that only gets installed with pypy, and it needs to be
# initialized for it to work properly. It mimic `psycopg2` 1-to-1
from psycopg2cffi import compat
compat.register()
USING_POSTGRES = True
except ImportError:
USING_POSTGRES = False

if USING_POSTGRES:
pg_database = 'alch_' + os.environ.get('POSTGRES_DATABASE', 'factory_boy_test')
pg_user = os.environ.get('POSTGRES_USER', 'postgres')
pg_password = os.environ.get('POSTGRES_PASSWORD', 'password')
pg_host = os.environ.get('POSTGRES_HOST', 'localhost')
pg_port = os.environ.get('POSTGRES_PORT', '5432')
engine_name = f'postgresql+psycopg2://{pg_user}:{pg_password}@{pg_host}:{pg_port}/{pg_database}'
else:
engine_name = 'sqlite://'
engine_name = 'sqlite://'

session = scoped_session(sessionmaker())
engine = create_engine(engine_name)
Expand Down
41 changes: 0 additions & 41 deletions tests/djapp/settings_pg.py

This file was deleted.

13 changes: 0 additions & 13 deletions tests/test_alchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
except ImportError:
raise unittest.SkipTest("sqlalchemy tests disabled.")

from sqlalchemy_utils import create_database, database_exists, drop_database

import factory
from factory.alchemy import SQLAlchemyModelFactory

Expand Down Expand Up @@ -77,17 +75,6 @@ class Meta:
text = factory.Sequence(lambda n: "text%s" % n)


if models.USING_POSTGRES:
# sqlite test database gets created/destroyed automatically, postgres does not.

def setUpModule():
if not database_exists(models.engine.url):
create_database(models.engine.url)

def tearDownModule():
drop_database(models.engine.url)


class TransactionTestCase(unittest.TestCase):
def setUp(self):
models.Base.metadata.create_all(models.engine)
Expand Down
25 changes: 6 additions & 19 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ envlist =
docs
examples
linkcheck
py{38,39,310,311,312,py39,py310}-sqlite
py{38,39,310,311,py39,py310}-django32-mongo-alchemy-{sqlite,postgres}
py{38,39,310,311,312}-django42-mongo-alchemy-{sqlite,postgres}
py{py39,py310}-django42-mongo-alchemy-sqlite,
# py{py39,py310}-django42-mongo-alchemy-postgres # TODO: Fix me!
py{310,311,312}-django50-mongo-alchemy-{sqlite,postgres}
py310-djangomain-mongo-alchemy-{sqlite,postgres}
py{38,39,310,311,312,py39,py310}
py{38,39,310,311,py39,py310}-django32-mongo-alchemy
py{38,39,310,311,312}-django42-mongo-alchemy
py{py39,py310}-django42-mongo-alchemy
py{310,311,312}-django50-mongo-alchemy
py310-djangomain-mongo-alchemy

[gh-actions]
python =
Expand All @@ -23,32 +22,20 @@ python =
pypy-3.9: pypy39
pypy-3.10: pypy310

[gh-actions:env]
DATABASE_TYPE =
sqlite: sqlite
postgres: postgres

[testenv]
passenv =
POSTGRES_HOST
POSTGRES_DATABASE
deps =
mypy
alchemy: SQLAlchemy
alchemy: sqlalchemy_utils
mongo: mongoengine
mongo: mongomock
django{32,42,50,main}: Pillow
django32: Django>=3.2,<3.3
django42: Django>=4.2,<5.0
django50: Django>=5.0,<5.1
djangomain: https://github.com/django/django/archive/main.tar.gz
py{38,39,310,311,312}-postgres: psycopg2-binary
pypy{39,310}-postgres: psycopg2cffi

setenv =
py: DJANGO_SETTINGS_MODULE=tests.djapp.settings
postgres: DJANGO_SETTINGS_MODULE=tests.djapp.settings_pg

allowlist_externals = make
commands = make test
Expand Down

0 comments on commit 35e4f9d

Please sign in to comment.