Assert 对于 Python 来说是不相等的。在测试中如何表达“不等于”?

问题描述 投票:0回答:1

我正在

django
中测试我的代码,我有一个案例,我想测试它是否
is NOT equal

我该怎么做?

我正在使用来自

django
的文档: https://docs.djangoproject.com/fr/2.2/topics/testing/tools/

React
中的另一个例子,我们有
.not
表示不等于。

我尝试过

.not

class SimpleTest(TestCase):
    def test_details(self):
        response = self.client.get('/customer/details/')
        self.assertEqual(response.status_code, 200).not()

我预计会有一个条件,即测试

not equality between my variable and my status code.

python django testing assert
1个回答
1
投票

@DanielRoseman 的解决方案正在运行。 使用assertNotEqual解决了问题

文档:https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertNotEqual

© www.soinside.com 2019 - 2024. All rights reserved.