是否应将try-except与self.fail一起使用

时间:2019-03-11 13:56:35

标签: python-3.x unit-testing

能否请您告诉我使用“ self.fail,这是一种单元测试的方法”的最佳实践??

我不知道是否应该将self.fail与try-except一起使用。

# django-tdd/functional_test.py
# https://github.com/gkzz/django-tdd/blob/chapter2-feature-unittest/functional_test.py
def test_can_start_a_list_and_retrieve_it_later(self):
    LOCAL_HOST_URL = 'http://127.0.0.1:8000/'
    self.driver.get(LOCAL_HOST_URL)
    # Pattern A (with try-except)
    try:
        self.assertIn('Django', self.driver.title)
    except:
       self.fail('fail the test')

    # Pattern B (said by "Test-Driven Development with Python")
    self.assertIn('Django', self.driver.title)
    self.fail('fail the test')

0 个答案:

没有答案