PythonUnitTest:为否定测试用例寻找断言信息

PythonUnitTest:为否定测试用例寻找断言信息,python,python-3.x,unit-testing,python-unittest,testcase,Python,Python 3.x,Unit Testing,Python Unittest,Testcase,我的案子有点复杂。我有几个测试,检查路由器和交换机上的某些登录过程 设置: import testcore (package that used Paramiko) from testcore.control.ssh import SSH import unittest from test import support import logging import os 在这里,您可以看到我的一个测试用例: def test_create_user_ENFORCE_2(self): i

我的案子有点复杂。我有几个测试,检查路由器和交换机上的某些登录过程

设置:

import testcore (package that used Paramiko)
from testcore.control.ssh import SSH
import unittest
from test import support
import logging
import os
在这里,您可以看到我的一个测试用例:

def test_create_user_ENFORCE_2(self):

    if self.s.login():

        q=self.s.query('account')
        self.assertIsNotNone(q, 'missing answer')
        #self.assertEqual('\r\n', q, 'unexpected result')


        # switch to prompt account

        q=self.s.query('add 15 testuser_ENFORCE_P1 ')
        self.assertIsNotNone(q, 'missing answer')
        #self.assertEqual('\r\n', q, 'unexpected result')
        self.assertTrue('class str')
        #self.assertTrue('The Password does not comply' != '\r\n\rERROR! The Password does not comply[240 chars]ar\n')
        #self.assertIs : True('The Password does not comply', q, 'add 15 testuser_ENFORCE_P1')
        print(type(q))
        q=self.s.query('logout')
        self.s.close()
测试按它应该的方式进行。他在相应的路由器/交换机上开始登录,并在提示符下执行命令

问题是:

  • 测试应检查I.u.a.特殊字符是否可以用作密码。如果是,则测试失败。积极的测试是我不能创建包含特殊字符的帐户
当前问题之后的唯一帮助是,我在路由器/交换机上收到以下消息

'密码不符合要求'!='\r\n\r错误!密码不正确 符合[240字符]ar\n'


我如何以及使用哪种断言可以做得最多?

我已经解决了这个问题,现参考以下内容:

import unittest


class TestClass(unittest.TestCase):
    def test_me(self):
        self.assertIn('me', 'you and me')
        self.assertIn('you', 'you and me')
        self.assertIn('and', 'you and me')
        self.assertNotIn('we', 'you and me')
        self.assertIn('we', 'you and me')


if __name__ == '__main__':
    unittest.main()

在我的测试中不允许使用以下特殊字符!#$%&'()*+,-./:;?@[]^^ `{124;}~)这应该由测试来查询,因此,如果您无法创建,用户可以将测试视为阳性。根据原则,我需要正确的断言,我可以在其中请求返回的文本或至少一半文本:我持有#self.assertTrue('ThePassword not Compliance'!='\r\n\rERROR!密码不符合[240个字符]ar\n')#self.asserts:True('ThePassword not Compliance',q,'add 15 testuser_ENFORCE_P1')表示这样做完全错误。