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

database creation not happening for LiveServerTestCase? #79

Closed
hjwp opened this issue Apr 10, 2014 · 6 comments
Closed

database creation not happening for LiveServerTestCase? #79

hjwp opened this issue Apr 10, 2014 · 6 comments
Milestone

Comments

@hjwp
Copy link
Contributor

hjwp commented Apr 10, 2014

Am in Holger's py.test tutorial at the PyCon. Thought I'd try to get py.test working on a small test repo, and it looks like django.test.TestCase tests are working fine, including those that need the test database, but classes from django.test.LiveServerTestCase seem not to be seeing the test database...

Maybe I'm just confused?

here's the test repo: https://github.com/hjwp/book-example/tree/chapter_07

you'll need a virtualenv built with python3, django 1.7 beta, and selenium:

mkvirtualenv pytest-py3-superlists --python=python3
pip install selenium pytest pytest-django https://www.djangoproject.com/download/1.7b1/tarball/

and then

py.test lists/tests.py  # normal django tests, work fine
py.test functional_tests.py  # liveserver tests, fail seemingly because no db
@pelme
Copy link
Member

pelme commented Apr 13, 2014

Thanks for the report!

I have been able to reproduce the issue: I have been able to run the tests successfully with "python manage.py test", but not with py.test. It seems like the database is not properly shared between the live server thread and the main thread.

A related issue is the lack of logging - I had to configure a debugging logger to get any information about what was going on. I will investigate if it is possible to set some sane defaults on the logger when running in tests, to have the exception information properly shown.

@hjwp
Copy link
Contributor Author

hjwp commented Apr 13, 2014

Nice one Andreas! I'll be at the pycon sprints tomorrow, are any of your contributors here?

re: the logging, i think that's django's fault. here's how i hack the logging settings to get stuff onto stderr... http://chimera.labs.oreilly.com/books/1234000000754/ch14.html#aside_logging_to_stderr

@pelme
Copy link
Member

pelme commented Apr 14, 2014

I am unfortunately not at pycon :(

It looks like @flub and Holger are organizing a pytest sprint:
https://twitter.com/hpk42/status/455329814837473280 (Floris is a pytest-django committer).

I am pelme on #pylib on Freenode and will try to respond/merge things as soon as I can too.

@flub
Copy link
Member

flub commented Apr 14, 2014

Hi, I haven't looked at this issue yet but do come along and I'll gladly help. The sprint certainly doesn't need to be restricted to py.test core

@pelme
Copy link
Member

pelme commented May 17, 2014

After spending some more time on this, I found the issue to a problem of how pytest handles the combination of setUpClass and autouse fixtures (which is used to setup the Django test database in pytest-django):

https://bitbucket.org/pytest-dev/pytest/issue/517/setup_-executed-before-all-fixtures
https://bitbucket.org/pytest-dev/pytest/pull-request/170/fix-for-issue517

When that issue gets solved, this should hopefully work. :-)

@pelme pelme added this to the 2.7 milestone Aug 25, 2014
@blueyed
Copy link
Contributor

blueyed commented Mar 12, 2015

In https://bitbucket.org/pytest-dev/pytest/issue/517/setup_-executed-before-all-fixtures#comment-14576060 it is mentioned that 8a9aacb fixes it.

@hjwp
Please re-open if that's not the case.

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

No branches or pull requests

4 participants