#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)
Change History (11)
comment:1 by , 10 years ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
by , 10 years ago
Attachment: | 24290.diff added |
---|
comment:2 by , 10 years ago
Has patch: | set |
---|---|
Owner: | set to |
Status: | new → assigned |
Added conditional import for psycopg2 and @skipIf on tests.
comment:3 by , 10 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 , 10 years ago
Attachment: | 24290-exploration.diff added |
---|
comment:4 by , 10 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:6 by , 10 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 , 10 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 , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Patch