#27117 closed Bug (invalid)
The force_login() does not work in a testing if using more one a test
Reported by: | Seti | Owned by: | nobody |
---|---|---|---|
Component: | Testing framework | Version: | 1.9 |
Severity: | Normal | Keywords: | Pytest, LiveTests |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
# test_.py
from django.test import Client from django.contrib.auth import get_user_model from django.core.management import call_command from django.contrib.staticfiles.testing import StaticLiveServerTestCase class Tests(StaticLiveServerTestCase): @classmethod def setUpClass(cls): super(Tests, cls).setUpClass() # a command for create a superuser for a testing call_command('factory_test_superusers', '1') cls.active_superuser = get_user_model().objects.get() def setUp(self): c = Client() c.force_login(self.active_superuser) def test_1(self): pass def test_2(self): pass
# run tests
py.test
traceback is here https://bpaste.net/show/36be7958e3d9
Change History (2)
comment:1 by , 8 years ago
Description: | modified (diff) |
---|
comment:2 by , 8 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Type: | Uncategorized → Bug |
Note:
See TracTickets
for help on using tickets.
This looks like a bug in your test code -- you're creating a user in
setUpClass
so that object persists between test methods (see the warning about modifying objects in the TestCase.setUpTestData() docs). It may not be related to the issue, but the test client isn't designed for use inStaticLiveServerTestCase
. See TicketClosingReasons/UseSupportChannels for ways to get help.