Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 1.8 Support #189

Closed
DavidMuller opened this issue Dec 27, 2014 · 8 comments
Closed

Django 1.8 Support #189

DavidMuller opened this issue Dec 27, 2014 · 8 comments

Comments

@DavidMuller
Copy link

Do you guys have a preliminary plan for supporting Django 1.8?

pytest-django is throwing:

 Failed: Database access not allowed, use the "django_db" mark to enable

all over the place for Django 1.8 builds of Django Rest Framework (see failed build example).

I was also having trouble getting even a simple project going (see repository):

from django.test import TestCase

class FirstTestClass(TestCase):
    def test_one(self):
        self.assertEquals(0, 0)
python manage.py test

Creating test database for alias 'default'...
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

Same test fails with py.test:

../../Envs/failure/lib/python2.7/site-packages/django/db/backends/__init__.py:151: in _cursor
    return self.create_cursor()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <django.db.backends.sqlite3.base.DatabaseWrapper object at 0x104f24ad0>

    def create_cursor(self):
>       return self.connection.cursor(factory=SQLiteCursorWrapper)
E       ProgrammingError: Cannot operate on a closed database.

../../Envs/failure/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py:425: ProgrammingError
================================================================== 1 error in 0.17 seconds ===================================================================

I believe the Django 1.8 feature freeze is Jan 12th.

@jezdez
Copy link
Contributor

jezdez commented Dec 28, 2014

It seems as if django/django@119154c breaks the marker somehow. Trying to investigate..

@DavidMuller
Copy link
Author

Yes, I have a feeling it is indeed related to the refactor of Django's TestCase

@pelme
Copy link
Member

pelme commented Dec 31, 2014

It is related to the Django change, and also pytest-django issue #79, #117.

pytest-django does not (currently) properly handle database access that happens in setUpClass. pytest-django manages database access via pytest fixtures and does not have any direct knowledge of setUp/setUpClass each other, which makes the solution a bit more tricky.

This is also discussed in this pytest issue:
https://bitbucket.org/hpk42/pytest/issue/517/setup_-executed-before-all-fixtures

My current plan is to avoid to intercept calls to setUpClass and to call setUpClass from an autouse fixture which can properly enable the database cursor at the correct time. I will try to look into this in the next couple of days and push a new release as soon as it is fixed.

@pelme pelme closed this as completed in 8a9aacb Jan 2, 2015
@pelme
Copy link
Member

pelme commented Jan 2, 2015

setUpClass should now be properly supported, but there are a bunch of tricky things involved here and I would really appreciate if you could give the current master a try before I put out a new version.

I also stumbled upon a Django bug (not directly related to this issue).
#191 / https://code.djangoproject.com/ticket/24069 A review of that issue/patch would be helpful :)

There are also another test failure for the latest Django master that I hope can fix soon!

@pelme
Copy link
Member

pelme commented Jan 2, 2015

Ok, all tests are now passing, if you could give this a try with your 1.8 projects that would be really helpful.

Here is a one-liner to install the latest version:

pip install -e git+https://github.com/pytest-dev/pytest-django.git#egg=pytest-django

@DavidMuller
Copy link
Author

Wow, thanks for such a quick fix. I am not near my machine at the moment, but will be there later today and can try it out.

@DavidMuller
Copy link
Author

I can confirm that the dirt simple Django 1.8 app that I referenced in the initial post of this thread now works (repo).

A build of Django Rest Framework master with Django 1.8 also appears to be free of pytest-django related errors.

👍

@pelme
Copy link
Member

pelme commented Jan 3, 2015

Good to hear! I plan to merge a couple of other changes and have a new release today or tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants