[Django] #19869: Add ability to restart LiveServerThread inside a test method

20 views
Skip to first unread message

Django

unread,
Feb 20, 2013, 6:12:11 PM2/20/13
to django-...@googlegroups.com
#19869: Add ability to restart LiveServerThread inside a test method
-----------------------------------+--------------------
Reporter: void | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------
I was trying to make a selenium test to work with different locales in one
test, like this:
{{{
for locale in locale_list:
with translation.override(locale):
self.selenium.get(something)
...test something...
}}}
But translation.override had affected only current thread, not
LiveServerThread, probably because active translation is thread-local.
Because I see no way to force LiveServerThread copy or share same thread-
local state, it would be cool if I could have ability to stop
LiveServerThread and recreate it in such cases. Currently it is
started/stopped in setUpClass/tearDownClass which means that it is created
once per TestCase run and shared between all the runs of all the test
methods.

--
Ticket URL: <https://code.djangoproject.com/ticket/19869>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 21, 2013, 2:47:28 AM2/21/13
to django-...@googlegroups.com
#19869: Add ability to restart LiveServerThread inside a test method
-----------------------------------+--------------------------------------

Reporter: void | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by aaugustin):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Can you set the Accept-Language header in the request, or use your
website's "change language" feature?

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:1>

Django

unread,
Feb 21, 2013, 7:23:56 AM2/21/13
to django-...@googlegroups.com
#19869: Add ability to restart LiveServerThread inside a test method
-----------------------------------+--------------------------------------

Reporter: void | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------

Comment (by void):

Selenium does not let you set custom request headers:
http://code.google.com/p/selenium/issues/detail?id=141.
I am actually trying to test django admin, it have no such "change
language" feature.

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:2>

Django

unread,
Feb 21, 2013, 4:13:21 PM2/21/13
to django-...@googlegroups.com
#19869: Add ability to restart LiveServerThread inside a test method
-----------------------------------+------------------------------------

Reporter: void | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by julien):

* stage: Unreviewed => Accepted


Comment:

I think one good way of doing this is to add a new method
"`activate_live_server_locale(self, locale)`" to `LiveServerTestCase` that
would activate the locale in the separate thread. It would be even better
if it could work as a context manager like so:

{{{#!python
class MyTests(LiveServerTestcase):

def test_something(self):
with self.activate_live_server_locale('de'):
...
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:3>

Django

unread,
Feb 21, 2013, 4:16:20 PM2/21/13
to django-...@googlegroups.com
#19869: Add ability to restart LiveServerThread inside a test method
-----------------------------------+------------------------------------

Reporter: void | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by julien):

By the way, "activate_live_server_locale" is a bit of a mouthful, so
suggestions for beter names are welcome ;)

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:4>

Django

unread,
Nov 14, 2013, 5:21:13 AM11/14/13
to django-...@googlegroups.com
#19869: Add ability to restart LiveServerThread inside a test method
-----------------------------------+------------------------------------

Reporter: void | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by unaizalakain):

How would you modify the thread local of the live server thread from the
main thread?

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:5>

Django

unread,
Nov 14, 2013, 5:25:12 AM11/14/13
to django-...@googlegroups.com
#19869: Add ability to restart LiveServerThread inside a test method
-----------------------------------+------------------------------------

Reporter: void | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by void):

With some kind of message or signal, I think

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:6>

Django

unread,
Nov 19, 2013, 1:26:50 PM11/19/13
to django-...@googlegroups.com
#19869: Add ability to restart LiveServerThread inside a test method
-----------------------------------+------------------------------------

Reporter: void | Owner: nobody
Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by unaizalakain):

I believe (though I may be wrong) that signals don't work across threads.

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:7>

Django

unread,
Dec 3, 2013, 3:52:13 PM12/3/13
to django-...@googlegroups.com
#19869: Add ability to restart LiveServerThread inside a test method
-------------------------------------+-------------------------------------
Reporter: void | Owner:
Type: New feature | unaizalakain
Component: Testing framework | Status: assigned
Severity: Normal | Version: master
Keywords: | Resolution:
Has patch: 0 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by unaizalakain):

* owner: nobody => unaizalakain
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:8>

Django

unread,
Dec 3, 2013, 3:53:23 PM12/3/13
to django-...@googlegroups.com
#19869: Make changing the active language inside `LiveTestServerCase` possible

-------------------------------------+-------------------------------------
Reporter: void | Owner:
Type: New feature | unaizalakain
Component: Testing framework | Status: assigned
Severity: Normal | Version: master
Keywords: | Resolution:
Has patch: 0 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:9>

Django

unread,
Dec 3, 2013, 7:16:12 PM12/3/13
to django-...@googlegroups.com
#19869: Make changing the active language inside `LiveTestServerCase` possible
-------------------------------------+-------------------------------------
Reporter: void | Owner:
Type: New feature | unaizalakain
Component: Testing framework | Status: assigned
Severity: Normal | Version: master
Keywords: | Resolution:
Has patch: 1 | Triage Stage: Accepted

Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by unaizalakain):

* has_patch: 0 => 1


Comment:

PR sent: https://github.com/django/django/pull/2021

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:10>

Django

unread,
Dec 3, 2013, 7:34:05 PM12/3/13
to django-...@googlegroups.com
#19869: Make changing the active language inside `LiveTestServerCase` possible
-------------------------------------+-------------------------------------
Reporter: void | Owner:
Type: New feature | unaizalakain
Component: Testing framework | Status: assigned
Severity: Normal | Version: master
Keywords: | Resolution:
Has patch: 1 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by unaizalakain):

The ``set_language`` view could be used to change the live test server
thread language but that would mean adding some kind of new method to the
test case and the inability to use the already defined methods
(`django.utils.translation.override`, `django.utils.translation.activate`,
etc).

Instead, the PR opts for making the thread local that holds the current
active language a non-local. This is done in the two threads so suddenly
one thread is capable of accessing the other one's active language. This
is afterwards reverted to thread locals again.

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:11>

Django

unread,
Feb 13, 2014, 12:15:50 PM2/13/14
to django-...@googlegroups.com
#19869: Make changing the active language inside `LiveTestServerCase` possible
-------------------------------------+-------------------------------------
Reporter: void | Owner:
Type: New feature | unaizalakain
Component: Testing framework | Status: assigned
Severity: Normal | Version: master
Keywords: | Resolution:
Has patch: 1 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by apollo13):

* cc: apollo13 (added)


Comment:

I'd very much prefer a method which just sets the active language in the
other thread as suggested by julien. While the PR might work, it makes me
run away in fear.

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:12>

Django

unread,
Feb 13, 2014, 1:41:13 PM2/13/14
to django-...@googlegroups.com
#19869: Make changing the active language inside `LiveTestServerCase` possible
-------------------------------------+-------------------------------------
Reporter: void | Owner:
Type: New feature | unaizalakain
Component: Testing framework | Status: assigned
Severity: Normal | Version: master
Keywords: | Resolution:
Has patch: 1 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by unaizalakain):

Well, it surely isn't the most elegant way of doing it but defining some
special functions for changing the active language when those functions
already exist doesn't seem right to me either.

I think disabling the language thread-local in the testing environment
isn't too bad, after all, it's not needed.

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:13>

Django

unread,
Jun 5, 2014, 7:25:41 PM6/5/14
to django-...@googlegroups.com
#19869: Make changing the active language inside `LiveTestServerCase` possible
-------------------------------------+-------------------------------------
Reporter: void | Owner:
Type: New feature | unaizalakain
Component: Testing framework | Status: assigned
Severity: Normal | Version: master
Keywords: | Resolution:
Has patch: 1 | Triage Stage: Accepted
Needs tests: 0 | Needs documentation: 0
Easy pickings: 0 | Patch needs improvement: 1
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* needs_better_patch: 0 => 1


Comment:

If the patch makes apollo13 run, I guess it needs improvement. :-)

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:14>

Django

unread,
Jun 6, 2014, 4:11:42 AM6/6/14
to django-...@googlegroups.com
#19869: Make changing the active language inside `LiveTestServerCase` possible
-----------------------------------+------------------------------------
Reporter: void | Owner:

Type: New feature | Status: new
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by unaizalakain):

* status: assigned => new
* needs_better_patch: 1 => 0
* has_patch: 1 => 0
* owner: unaizalakain =>


Comment:

Then more than an improvement, I think a totally different patch is
needed, although I don't understand the need for a language thread-local
in a testing environment that doesn't support multithreading.

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:15>

Django

unread,
Jun 11, 2014, 11:38:56 AM6/11/14
to django-...@googlegroups.com
#19869: Make changing the active language inside `LiveTestServerCase` possible
-----------------------------------+------------------------------------
Reporter: void | Owner: gchp
Type: New feature | Status: assigned

Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by gchp):

* owner: => gchp


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:16>

Django

unread,
Feb 27, 2015, 1:01:32 PM2/27/15
to django-...@googlegroups.com
#19869: Make changing the active language inside `LiveTestServerCase` possible
-----------------------------------+------------------------------------
Reporter: void | Owner: gchp
Type: New feature | Status: assigned
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------

Comment (by void):

The initial goal of this ticket was to deal with issue that emerged while
working on the #18767.
That is, translation.override was not able to change thread-local state of
`LiveServerThread`, and it rendered everything in one language.
#18767 ticket is fixed now and thread-local issue resolved by introducing
settings_changed signal and its receivers, in particular to the
`trans_real._active = threading.local()` line in `django.test.signals`.

Therefore, I think it's safe to close this ticket as wontfix.

--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:17>

Django

unread,
Feb 27, 2015, 1:08:43 PM2/27/15
to django-...@googlegroups.com
#19869: Make changing the active language inside `LiveTestServerCase` possible
-----------------------------------+------------------------------------
Reporter: void | Owner: gchp
Type: New feature | Status: closed

Component: Testing framework | Version: master
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-----------------------------------+------------------------------------
Changes (by void):

* status: assigned => closed
* resolution: => wontfix


--
Ticket URL: <https://code.djangoproject.com/ticket/19869#comment:18>

Reply all
Reply to author
Forward
0 new messages