Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#24290 closed Cleanup/optimization (fixed)

postgres_tests fail ungracefully if psycopg2 isn't installed

Reported by: Aymeric Augustin Owned by: Joel Burton
Component: contrib.postgres Version: dev
Severity: Normal Keywords: 1.8-beta
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Uninstalling psycopg2 and running ./runtests.py postgres_tests shows a series of stack traces.

Would it be possible to make the imports conditional and skip the tests cleanly?

See template_backends/test_jinja2.py for an example.

Attachments (2)

24290.diff (9.2 KB ) - added by Joel Burton 9 years ago.
Patch
24290-exploration.diff (2.6 KB ) - added by Tim Graham 9 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 by Tim Graham, 9 years ago

Easy pickings: set
Triage Stage: UnreviewedAccepted

by Joel Burton, 9 years ago

Attachment: 24290.diff added

Patch

comment:2 by Joel Burton, 9 years ago

Has patch: set
Owner: set to Joel Burton
Status: newassigned

Added conditional import for psycopg2 and @skipIf on tests.

comment:3 by Tim Graham, 9 years ago

Easy pickings: unset
Keywords: 1.8 added
Patch needs improvement: set

There is a new problem on master (which affects 1.8 too, but it's a RemovedInDjango19Warning instead of a RuntimeError:

$ ./runtests.py postgres_tests
...
Model class postgres_tests.models.IntegerArrayModel doesn't declare
an explicit app_label and either isn't in an application in INSTALLED_APPS
or else was imported before its application was loaded.

It's caused by the hack in runtests.py to omit the postgres_tests app when not running with a postgresql database (to avoid trying to apply the migrations when not in postgresql). I'm attaching a patch I experimented with, but there are still unsolved problems with it.

by Tim Graham, 9 years ago

Attachment: 24290-exploration.diff added

comment:4 by Claude Paroz, 9 years ago

Also encountered:

  File "/home/claude/virtualenvs/djangogit/local/lib/python2.7/site-packages/django/contrib/postgres/forms/ranges.py", line 1, in <module>
    from psycopg2.extras import DateRange, DateTimeTZRange, NumericRange
ImportError: cannot import name DateRange
>>> psycopg2.__version__
'2.4.5 (dt dec mx pq3 ext)'

It might also depend on installed PostgreSQL extensions.

comment:5 by Claude Paroz, 9 years ago

Created #24335 for the DateRange import failure.

comment:6 by Tim Graham, 9 years ago

After looking into this a bit more (trying to remove the hack in runtests.py), I think it might be a better use of time to just skip postgres_tests entirely when not testing with the django.db.backends.postgresql_psycopg2 backend. While it's nice in theory to allow executing the non-database tests while testing with other backends, in practice it seems quite convoluted. Objections?

Maybe a separate test app (without any models) would be the way to go if there's a strong incentive to allow that.

comment:7 by Tim Graham, 9 years ago

Keywords: 1.8-beta added; 1.8 removed
Patch needs improvement: unset

PR to skip postgres_tests if not running with PostgreSQL.

comment:8 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 8b39f33d78ce5749f8ca40a7ae6823b5f6c26c09:

Fixed #24290 -- Skipped postgres_tests if not running with PostgreSQL.

comment:9 by Tim Graham <timograham@…>, 9 years ago

In a00a0f880485e1f122e48e0216d34d08efe199e1:

[1.8.x] Fixed #24290 -- Skipped postgres_tests if not running with PostgreSQL.

Backport of 8b39f33d78ce5749f8ca40a7ae6823b5f6c26c09 from master

Note: See TracTickets for help on using tickets.
Back to Top