gpt4 book ai didi

python - Nosetest 和 unittest.expectedFailures

转载 作者:行者123 更新时间:2023-11-28 19:13:08 25 4
gpt4 key购买 nike

我目前正在使用 Selenium、Python 和 nosetests 测试我的网站。成功测试一切正常,我在失败测试中遇到问题(我从未使用 Python/Selenium/Nosetest 进行过测试,所以......)。对于以下测试:

 @unittest.expectedFailure
def test_connection_failure(self):

# Fill the username with the login only
self.driver.find_element_by_id('form_identifiant').send_keys(test_login)

# Send the form
self.driver.find_element_by_id('form_submit').click()

# Check the landing URL
page_url = self.driver.current_url
self.assertEqual(page_url, page_home)

我正在测试一个非常简单的案例:当您只输入登录名时,您无法连接到该网站。因此,当我比较我当前的页面 URL 和如果登录名/密码对正确时我应该在的页面时,我确实失败了。

我从 nosetests 提示中收到以下消息:

[root@localhost AppGestion]# nosetests ConnectionTests.py
/usr/lib64/python2.7/unittest/case.py:380: RuntimeWarning: TestResult has no addExpectedFailure method, reporting as passes
RuntimeWarning)

我只是不明白这个错误。我在网上找到了“addExpectedFailure”方法,但没有找到如何使用它,把它放在哪里……我想知道,因为测试实际上只是被 nosetest 跳过了。

有什么线索吗?

最佳答案

nose 处理预期异常的装饰器是@raises(...):

http://nose.readthedocs.io/en/latest/testing_tools.html

但在您的情况下,您可以简单地使用 assertNotEqual 而无需装饰器:

def test_connection_failure(self):

# Fill the username with the login only
self.driver.find_element_by_id('form_identifiant').send_keys(test_login)

# Send the form
self.driver.find_element_by_id('form_submit').click()

# Check the landing URL
page_url = self.driver.current_url
self.assertNotEqual(page_url, page_home)

关于python - Nosetest 和 unittest.expectedFailures,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37431020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com