我想知道是否有人可以帮助找出为什么我的用户似乎没有登录。
import pytest
from mixer.backend.django import mixer
@pytest.fixture
def strong_pass():
return "Str#410-P@55"
@pytest.fixture
def create_test_user(db, strong_pass):
return mixer.blend('auth.User', username="JohnnyTest", password=strong_pass)
@pytest.fixture
def logged_in_client(client, create_test_user, strong_pass):
test_user = create_test_user
if test_user is not None:
client.login(username=test_user.username, password=strong_pass)
return client, test_user它使用户很好,并且可以在其他测试中引用他,但是客户端似乎不喜欢这种登录。
我尝试将client.login中的值替换为确切的字符串,但仍然不起作用。我也尝试过force_login,但仍然不起作用
任何帮助都将不胜感激
发布于 2020-07-05 22:33:24
找出了主要问题是由于混音器。
一旦我按照普通的文档登录pytest-django docs,我就得到了我的fixture。
https://pytest-django.readthedocs.io/en/latest/helpers.html#client-django-test-client
https://stackoverflow.com/questions/62739950
复制相似问题