Python:Tests and Setup do not get run

huangapple go评论79阅读模式
英文:

Python: Tests and Setup do not get run

问题

设置和测试方法似乎在我执行以下代码时都不运行。 有人能告诉我为什么吗?

class InstallTest():
    """Ru Ovirt System Tests"""

    def setUp(self):
        """Test Case Setup"""
        Log.test_objective('Hi!!!')
        self.client = Client(OSSE_OLV_TESTBOX_HOST, OSSE_OLV_TESTBOX_USER,
                             OSSE_OLV_TESTBOX_PASS)
        self.client.concurrency = OSSE_OLV_TESTBOX_CONCURRENCY

        self.log_jobdir = os.getenv('osse_log_jobdir')
        self.log_jobdir_cc = os.path.join(self.log_jobdir, 'config_collect')

        LOG.Log.test_setup('Instantiate Client object')
        self.client_mgmt = _list(OSSE_OFSS_CLIENT_MGMT)
        self.client_head_list = str(OSSE_OFSS_CLIENT_HEAD_LIST)
        if self.client_head_list == '-1':
            self.client_head_list = 0
        self.head = self.client_mgmt[int(self.client_head_list)]
        self.client = CLIENT.Client(self.head,
                                    OSSE_OFSS_CLIENT_USER,
                                    OSSE_OFSS_CLIENT_PASS)

        self.client_luniqname = str(OSSE_OFSS_LUN_UNIQNAME)
        self.vdbench_binary = str(OSSE_OFSS_VDBENCH_BINARY_PATH) + '/vdbench'
        self.vdbench_out_path = str(OSSE_OFSS_VDBENCH_OUT_PATH) + '/'
        template = str(OSSE_OFSS_VDBENCH_TEMPLATE_FILE)
        if template.startswith('/'):
            self.vdbench_template = template
        else:
            self.vdbench_template = \
                os.path.dirname(os.path.abspath(__file__)) + '/' + template

        self.host = self.client.hostname_get()
        msg = 'Setup the {0} client'.format(self.host)
        LOG.Log.test_setup(msg)

    def tearDown(self):
        self.client.close()

    def test_install_lago(self):        
        assert (1 == 1)
英文:

Both the setup and the test method do not seem to run when i execute the below code. Can anyone advise why this must be?

class InstallTest():
    """Ru Ovirt System Tests"""

    def setUp(self):
        """Test Case Setup"""
        Log.test_objective('Hi!!!')
        self.client = Client(OSSE_OLV_TESTBOX_HOST, OSSE_OLV_TESTBOX_USER,
                             OSSE_OLV_TESTBOX_PASS)
        self.client.concurrency = OSSE_OLV_TESTBOX_CONCURRENCY

        self.log_jobdir = os.getenv('osse_log_jobdir')
        self.log_jobdir_cc = os.path.join(self.log_jobdir, 'config_collect')

        LOG.Log.test_setup('Instantiate Client object')
        self.client_mgmt = _list(OSSE_OFSS_CLIENT_MGMT)
        self.client_head_list = str(OSSE_OFSS_CLIENT_HEAD_LIST)
        if self.client_head_list == '-1':
            self.client_head_list = 0
        self.head = self.client_mgmt[int(self.client_head_list)]
        self.client = CLIENT.Client(self.head,
                                    OSSE_OFSS_CLIENT_USER,
                                    OSSE_OFSS_CLIENT_PASS)

        self.client_luniqname = str(OSSE_OFSS_LUN_UNIQNAME)
        self.vdbench_binary = str(OSSE_OFSS_VDBENCH_BINARY_PATH) + '/vdbench'
        self.vdbench_out_path = str(OSSE_OFSS_VDBENCH_OUT_PATH) + '/'
        template = str(OSSE_OFSS_VDBENCH_TEMPLATE_FILE)
        if template.startswith('/'):
            self.vdbench_template = template
        else:
            self.vdbench_template = \
                os.path.dirname(os.path.abspath(__file__)) + '/' + template

        self.host = self.client.hostname_get()
        msg = 'Setup the {0} client'.format(self.host)
        LOG.Log.test_setup(msg)

    def tearDown(self):
        self.client.close()

    def test_install_lago(self):        
        assert (1 == 1)

The last assert is just put in as filler for now in case assert is necessary for test methods

答案1

得分: 3

Your class doesn't inherit a test case.

import unittest
class InstallTest(unittest.TestCase):
英文:

Your class doesn't inherit a test case.

import unittest
class InstallTest(unittest.TestCase):

答案2

得分: 1

首先,如Sayse已经回答的那样,你的类需要继承自unittest.TestCase。另外,除非这段代码是构建在某些已经包含自己的测试运行器的框架上(例如Django的manage.py test),你需要实际执行TestCase的测试方法:

import unittest

class YourTestCase(unittest.TestCase):
   # ...

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

注意,所有这些都有文档说明...

英文:

First, as already answsered by Sayse, your class needs to inherit from unittest.TestCase. Also, unless this code is built on some frameworks that already includes it's own testrunners (ie Django 'manage.py test'), you need to actually execute the TestCase test methods:

import unittest

class YourTestCase(unittest.TestCase):
   # ...

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

Note that all this is documented...

huangapple
  • 本文由 发表于 2020年1月6日 17:28:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/59609576.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定