英文:
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...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论