Would it be possible to make the imports conditional and skip the tests
cleanly?
See `template_backends/test_jinja2.py` for an example.
--
Ticket URL: <https://code.djangoproject.com/ticket/24290>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* easy: 0 => 1
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:1>
* status: new => assigned
* owner: => joelburton
* has_patch: 0 => 1
Comment:
Added conditional import for psycopg2 and @skipIf on tests.
--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:2>
* keywords: => 1.8
* needs_better_patch: 0 => 1
* easy: 1 => 0
Comment:
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
[https://github.com/django/django/blob/8ec306a3a90aa2ec0baa4c9d8df68f0d49947a2c/tests/runtests.py#L87-L88
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:3>
Comment (by claudep):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:4>
Comment (by claudep):
Created #24335 for the `DateRange` import failure.
--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:5>
Comment (by timgraham):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:6>
* keywords: 1.8 => 1.8-beta
* needs_better_patch: 1 => 0
Comment:
[https://github.com/django/django/pull/4157 PR] to skip `postgres_tests`
if not running with PostgreSQL.
--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"8b39f33d78ce5749f8ca40a7ae6823b5f6c26c09"]:
{{{
#!CommitTicketReference repository=""
revision="8b39f33d78ce5749f8ca40a7ae6823b5f6c26c09"
Fixed #24290 -- Skipped postgres_tests if not running with PostgreSQL.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:8>
Comment (by Tim Graham <timograham@…>):
In [changeset:"a00a0f880485e1f122e48e0216d34d08efe199e1"]:
{{{
#!CommitTicketReference repository=""
revision="a00a0f880485e1f122e48e0216d34d08efe199e1"
[1.8.x] Fixed #24290 -- Skipped postgres_tests if not running with
PostgreSQL.
Backport of 8b39f33d78ce5749f8ca40a7ae6823b5f6c26c09 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24290#comment:9>