Opened 8 years ago

Closed 8 years ago

Last modified 8 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)

# 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 Seti, 8 years ago

Description: modified (diff)

comment:2 by Tim Graham, 8 years ago

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. 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.

Version 0, edited 8 years ago by Tim Graham (next)
Note: See TracTickets for help on using tickets.
Back to Top