Nosetest和unittest.expectedFailures [英] Nosetest and unittest.expectedFailures
问题描述
我目前正在使用Selenium,Python和鼻子测试来测试我的网站.对于成功的测试,一切正常,我在失败测试中遇到了问题(我从未使用Python/Selenium/Nosetest进行过测试……). 对于以下测试:
I am currently testing my website with Selenium, Python and nosetests. Everything works fine for success tests, I got a problem on failure tests (I have never test with Python / Selenium / Nosetest so ...). For the following test :
@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和登录名/密码对正确的页面时,除了失败之外,我没有做其他事情.
I am testing a very simple case : when you enter only a login, you can't connect to the website. So I do except a failure when I compare my current page URL and the page where I should be if the login / password couple were correct.
我从鼻子测试提示中收到以下消息:
I got the following message from nosetests prompt :
[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"方法,但没有找到如何使用它,放在何处……我想这样做是因为实际上鼻子测试只是跳过了该测试.
I just don't understand this error. I found the "addExpectedFailure" method on the net but didn't found how to use it, where to put it ... I would like to because the test is just skipped by nosetest actually.
有任何线索吗?
推荐答案
使用nose
处理预期异常的装饰器是@raises(...)
:
The decorator with nose
to handle an expected exception is @raises(...)
:
http://nose.readthedocs.io/en/latest/testing_tools.html
但是在您的情况下,您可以简单地使用assertNotEqual
而不使用装饰器:
But in your case, you could simply use assertNotEqual
without the decorator:
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)
这篇关于Nosetest和unittest.expectedFailures的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!