python - Nosetest 和 unittest.expectedFailures

标签 python unit-testing selenium nose

我目前正在使用 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/

相关文章:

selenium - 使用selenium查找具有多个类的元素的存在

ios - 出现 "Use current location"权限弹窗时 Appium 和 Selenium 连接失败

python - 使用 pyinstaller 后执行编译文件 "No module named ' scipy._lib.messagestream' 时出错

python - 如何解压元素列表

python - 将脚本的目录添加到字符串中

python - 如何跳过文档字符串中包含某些文本的测试?

python - Selenium 无法打开 Firefox 48.0.1

python - django/whitenoise 存储后端导致错误

c# - 我应该在编译之前编写测试吗?

unit-testing - 测试一个 go 闭包