Python:Tests and Setup do not get run

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

Python: Tests and Setup do not get run

问题

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

  1. class InstallTest():
  2. """Ru Ovirt System Tests"""
  3. def setUp(self):
  4. """Test Case Setup"""
  5. Log.test_objective('Hi!!!')
  6. self.client = Client(OSSE_OLV_TESTBOX_HOST, OSSE_OLV_TESTBOX_USER,
  7. OSSE_OLV_TESTBOX_PASS)
  8. self.client.concurrency = OSSE_OLV_TESTBOX_CONCURRENCY
  9. self.log_jobdir = os.getenv('osse_log_jobdir')
  10. self.log_jobdir_cc = os.path.join(self.log_jobdir, 'config_collect')
  11. LOG.Log.test_setup('Instantiate Client object')
  12. self.client_mgmt = _list(OSSE_OFSS_CLIENT_MGMT)
  13. self.client_head_list = str(OSSE_OFSS_CLIENT_HEAD_LIST)
  14. if self.client_head_list == '-1':
  15. self.client_head_list = 0
  16. self.head = self.client_mgmt[int(self.client_head_list)]
  17. self.client = CLIENT.Client(self.head,
  18. OSSE_OFSS_CLIENT_USER,
  19. OSSE_OFSS_CLIENT_PASS)
  20. self.client_luniqname = str(OSSE_OFSS_LUN_UNIQNAME)
  21. self.vdbench_binary = str(OSSE_OFSS_VDBENCH_BINARY_PATH) + '/vdbench'
  22. self.vdbench_out_path = str(OSSE_OFSS_VDBENCH_OUT_PATH) + '/'
  23. template = str(OSSE_OFSS_VDBENCH_TEMPLATE_FILE)
  24. if template.startswith('/'):
  25. self.vdbench_template = template
  26. else:
  27. self.vdbench_template = \
  28. os.path.dirname(os.path.abspath(__file__)) + '/' + template
  29. self.host = self.client.hostname_get()
  30. msg = 'Setup the {0} client'.format(self.host)
  31. LOG.Log.test_setup(msg)
  32. def tearDown(self):
  33. self.client.close()
  34. def test_install_lago(self):
  35. 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?

  1. class InstallTest():
  2. """Ru Ovirt System Tests"""
  3. def setUp(self):
  4. """Test Case Setup"""
  5. Log.test_objective('Hi!!!')
  6. self.client = Client(OSSE_OLV_TESTBOX_HOST, OSSE_OLV_TESTBOX_USER,
  7. OSSE_OLV_TESTBOX_PASS)
  8. self.client.concurrency = OSSE_OLV_TESTBOX_CONCURRENCY
  9. self.log_jobdir = os.getenv('osse_log_jobdir')
  10. self.log_jobdir_cc = os.path.join(self.log_jobdir, 'config_collect')
  11. LOG.Log.test_setup('Instantiate Client object')
  12. self.client_mgmt = _list(OSSE_OFSS_CLIENT_MGMT)
  13. self.client_head_list = str(OSSE_OFSS_CLIENT_HEAD_LIST)
  14. if self.client_head_list == '-1':
  15. self.client_head_list = 0
  16. self.head = self.client_mgmt[int(self.client_head_list)]
  17. self.client = CLIENT.Client(self.head,
  18. OSSE_OFSS_CLIENT_USER,
  19. OSSE_OFSS_CLIENT_PASS)
  20. self.client_luniqname = str(OSSE_OFSS_LUN_UNIQNAME)
  21. self.vdbench_binary = str(OSSE_OFSS_VDBENCH_BINARY_PATH) + '/vdbench'
  22. self.vdbench_out_path = str(OSSE_OFSS_VDBENCH_OUT_PATH) + '/'
  23. template = str(OSSE_OFSS_VDBENCH_TEMPLATE_FILE)
  24. if template.startswith('/'):
  25. self.vdbench_template = template
  26. else:
  27. self.vdbench_template = \
  28. os.path.dirname(os.path.abspath(__file__)) + '/' + template
  29. self.host = self.client.hostname_get()
  30. msg = 'Setup the {0} client'.format(self.host)
  31. LOG.Log.test_setup(msg)
  32. def tearDown(self):
  33. self.client.close()
  34. def test_install_lago(self):
  35. 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.

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

Your class doesn't inherit a test case.

  1. import unittest
  2. class InstallTest(unittest.TestCase):

答案2

得分: 1

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

  1. import unittest
  2. class YourTestCase(unittest.TestCase):
  3. # ...
  4. if __name__ == "__main__":
  5. 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:

  1. import unittest
  2. class YourTestCase(unittest.TestCase):
  3. # ...
  4. if __name__ == "__main__":
  5. 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:

确定