简体   繁体   中英

ImportError during unittest script

I'm trying to set some tests for my server.

According to a friend's recommendation I wanna use unittest and mock. For this purpose I wrote some lines but when I try to execute the script I got an importError.

Traceback (most recent call last):
  File "test_creds.py", line 146, in <module>
    unittest.main()       
AttributeError: 'module' object has no attribute 'main'

Do I have some mistake with the imports?

Thanks!

# coding=utf-8

import sys, os
import unittest, mock, kiss

from twisted.python import log
from twisted.trial import unittest
from twisted.cred import credentials

class CredentialsChecker(unittest.TestCase):

    """
    Testing the server credentials handling
    """

    def _setUp_databases(self):           
        username_1 = 'user_name'
        password_1 = 'user_pass'
        email_1 = 'user@mail.org'

        create_user_profile = mock.Mock()

        self.db = mock.Mock()

        self.db.username = username_1
        self.db.password = password_1
        self.db.email = email_1

    def setUp(self):
        log.startLogging(sys.stdout)

        log.msg(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Flushing database")
        #management.execute_from_command_line(['manage.py', 'flush',\
#'--noinput'])

        log.msg(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Populating database")
        #management.execute_from_command_line(['manage.py', 'createsuperuser',\
#'--username', 'superuser_name', '--email', 'superuser_name@email.org',\
#'--noinput'])
        self._setUp_databases()

        log.msg(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Running tests")
        return

    """
    Log in with valid credentianls. The server should return True
    """
        def test_GoodCredentials(self):

        creds = credentials.UsernamePassword('user_name', 'user_pass')
        checker = DjangoAuthChecker()
        d = checker.requestAvatarId(creds)

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

如果创建从unittest.TestCase测试类继承的对象,则必须使用本机Python unittest模块。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM