#24965: Make LiveServerTestCase.live_server_url accessible from class
-------------------------------------+-------------------------------------
Reporter: MoritzS | Owner: MoritzS
Type: | Status: assigned
Cleanup/optimization |
Component: Testing framework | Version: master
Severity: Normal | Resolution:
Keywords: selenium tests live | Triage Stage:
server test case url | Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by timgraham):
Would an approach like this be better than adding a method?
{{{
diff --git a/django/test/testcases.py b/django/test/testcases.py
index b17b392..22ab3c1 100644
--- a/django/test/testcases.py
+++ b/django/test/testcases.py
@@ -1245,6 +1245,13 @@ class LiveServerThread(threading.Thread):
self.httpd.server_close()
+class classproperty(object):
+ def __init__(self, f):
+ self.f = f
+ def __get__(self, obj, owner):
+ return self.f(owner)
+
+
class LiveServerTestCase(TransactionTestCase):
"""
Does basically the same as TransactionTestCase but also launches a
live
@@ -1259,7 +1266,7 @@ class LiveServerTestCase(TransactionTestCase):
static_handler = _StaticFilesHandler
- @property
+ @classproperty
def live_server_url(self):
return 'http://%s:%s' % (
self.server_thread.host, self.server_thread.port)
}}}
Is it okay for the attribute to fail when not using `setUpClass`? For
example:
{{{
>>> from django.test.testcases import LiveServerTestCase
>>> LiveServerTestCase.live_server_url
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/tim/code/django/django/test/testcases.py", line 1252, in
__get__
return self.f(owner)
File "/home/tim/code/django/django/test/testcases.py", line 1272, in
live_server_url
self.server_thread.host, self.server_thread.port)
AttributeError: type object 'LiveServerTestCase' has no attribute
'server_thread'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24965#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.2681a4e9b26cbb4cebd27d8ca9f80eae%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.