Opened 4 years ago

Closed 4 years ago

#22595 closed Uncategorized (needsinfo)

LiveServerTestCase concurrency

Reported by: anonymous Owned by: nobody
Component: Documentation Version: 1.6
Severity: Normal Keywords:
Cc: werner@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I love the live tests but they run concurrently and it's no clearly written in the section:
https://docs.djangoproject.com/en/dev/topics/testing/tools/#django.test.LiveServerTestCase

I know it's written for the basic tests. I'd suggest to include something like:

Those tests run in parallel by default. If you need to change the database, consider inheriting from
django.test.LiveServerTestCase as well as django.test.TestCase (see section above about TestCase).

Change History (7)

comment:1 Changed 4 years ago by Werner Beroux

comment:2 Changed 4 years ago by Werner Beroux

Cc: werner@… added

comment:3 Changed 4 years ago by Tim Graham

I'm not sure exactly what you're suggesting. Can you explain a bit more? There's the note at the bottom of the section you linked that seems like it might be related: "When using an in-memory SQLite database to run the tests, the same database connection will be shared by two threads in parallel."

I'm not so sure about the advice to inherit from both LiveServerTestCase and TestCase either.

comment:4 Changed 4 years ago by Werner Beroux

It's not the issue I had. Even with Postgres It runs tests in parallel on the same database it seems. That's an issue, as system tests using selenium will often change the database. So I had to extend from the Django test case too as described on that class description.

comment:5 Changed 4 years ago by Tim Graham

I'm still not sure what the problem is you are trying to describe. Django's test suite has tests that inherit from LiveServerTestCase which modify the database, see tests/admin_widgets/tests.py for examples. Can you include an example tests that demonstrates the issue?

comment:6 Changed 4 years ago by anonymous

Yes I see that [LiveServerTestCase]^-[StaticLiveServerCase]^-[AdminSeleniumWebDriverTestCase] however the DB changes look minimal. What I did in use Django-CMS and in my setUp() I create the Page cms.api.create_page('root', template, 'en', published=True) and a few other things like that.

I've multiple classes inheriting LiveServerTestCase. If I do manage.py test <single.class.path.here> it usually works. If I run all tests, it fails nearly all the time. Then I saw on https://docs.djangoproject.com/en/dev/topics/testing/tools/#testcase that it wraps each test in a transaction. One of the notes gave me the hint.

I probably need to read the rest of the documentation to understand how the DB are setup for each test and how I might run them in parallel. I would expect LiveServerTestCase to help a little bit on system tests (like WebDriver tests) by may be an example with such setUp. For example: Will all tests run in parallel on the same database? For example TransactionTestCase is said to truncate all tables, but if it's done on the same DB by two tests concurrently how can that work properly?

In the end even my solution works, but it seems I'm better off using Django test fixtures.

comment:7 Changed 4 years ago by Tim Graham

Resolution: needsinfo
Status: newclosed

I guess this may be a bug in your application code, but I'm still not quite sure. If you can pin down the details, please reopen the ticket. As it stands, I am not sure what documentation, if any, we should be adding. You might find ticket #20461 of interest (Support for running Django tests in parallel).

Our support channels may also be of help:
https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels

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