首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pytest-Django客户端用户登录

Pytest-Django客户端用户登录
EN

Stack Overflow用户
提问于 2020-07-05 19:17:42
回答 1查看 1.9K关注 0票数 1

我想知道是否有人可以帮助找出为什么我的用户似乎没有登录。

代码语言:javascript
复制
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,但仍然不起作用

任何帮助都将不胜感激

EN

回答 1

Stack Overflow用户

发布于 2020-07-05 22:33:24

找出了主要问题是由于混音器。

一旦我按照普通的文档登录pytest-django docs,我就得到了我的fixture。

https://pytest-django.readthedocs.io/en/latest/helpers.html#client-django-test-client

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62739950

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档