Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#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 Seti)


from django.test import Client
from django.contrib.auth import get_user_model
from import call_command
from django.contrib.staticfiles.testing import StaticLiveServerTestCase

class Tests(StaticLiveServerTestCase):

    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()

    def test_1(self):

    def test_2(self):

# run tests


traceback is here

Change History (2)

comment:1 Changed 3 years ago by Seti

Description: modified (diff)

comment:2 Changed 3 years ago by Tim Graham

Resolution: invalid
Status: newclosed
Type: UncategorizedBug

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 in StaticLiveServerTestCase. See TicketClosingReasons/UseSupportChannels for ways to get help.

Last edited 3 years ago by Tim Graham (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top