我目前正在用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和我应该在哪里的页面时,如果登录/密码对是正确的。
我从鼻子测试提示得到以下信息:
[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”方法,但是没有找到如何使用它,把它放在哪里。。。我想这样做是因为鼻子测试实际上跳过了测试。
有线索吗?

最佳答案

nose处理预期异常的装饰符是@raises(...)
http://nose.readthedocs.io/en/latest/testing_tools.html
但是在您的例子中,您可以简单地使用assertNotEqual而不使用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)

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

10-09 17:12
查看更多