- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
类似于this question .但是,在使用 ddt 时,接受的解决方案对我不起作用.
例如:
def numbers_to_words(num):
if(num == 1): return 'One'
if(num == 2): return 'Two'
if(num == 3): return 'Three'
raise Error
@ddt
class TestNumbersToWords(unittest.TestCase):
@unpack
@data((1, 'One'), (2, 'Two'), (3, 'Three'))
def test_should_return_correct_word(self, input, expected):
self.assertEqual(expected, numbers_to_words(input))
如果我在终端中运行它,它不起作用
python3 testSuite.py TestNumbersToWords.test_should_return_correct_word
最佳答案
这是因为 ddt
正在“更改”测试名称的方式。如果您在详细模式下运行测试,您将看到:
$ python testSuite.py -v
test_should_return_correct_word_1__1___One__ (__main__.TestNumbersToWords) ... ok
test_should_return_correct_word_2__2___Two__ (__main__.TestNumbersToWords) ... ok
test_should_return_correct_word_3__3___Three__ (__main__.TestNumbersToWords) ... ok
----------------------------------------------------------------------
Ran 3 tests in 0.000s
OK
如您所见,test_should_return_correct_word
在这里不存在。但是您可以提供正在运行的方法的真实名称,它将起作用:
$ python test_a.py TestNumbersToWords.test_should_return_correct_word_1__1___One__
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
但是您将无法运行所有匹配模式的测试,例如 TestNumbersToWords.test_should_return_correct_word*
。
关于python - 通过命令行从 unittest.TestCase 运行单个测试 - 使用 ddt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40703695/
在开发 API 时,我经常在 main 函数中编写测试代码,但因为 D 已经集成了 unittest,所以我想开始使用它们。 我当前的工作流程如下,我有一个脚本可以监视任何 .d 文件中的文件更改,如
我无法使用 pub 包语法导入文件,如下所示: #import("package:unittest/unittest.dart"); 我收到以下编译时错误: 找不到引用的源:包:unittest/un
我想问一下我是否应该将我正在测试的函数包含在 unittest 文件中(这样我就会有一个文件 unittest.py),或者我应该只将它导入到 unittest 文件中(我会有两个文件、unittes
我正在尝试使用 C++/Codelite 进行单元测试。我从 codelite-plugins 包(Ubuntu 18.04)安装了 UnitTest++ 插件。我也可以看到这个: $ ls -la
我正在用 python 进行单元测试。我没有使用任何自动测试发现。我正在手动将 TestCases 组装到 TestSuite 中。 我可以用 unittest.TextTestRunner().ru
我正在尝试学习 Python 中的单元测试,特别是 unittest 模块。 考虑以下几行: import unittest class abc(unittest.TestCase): def
我正在开发一个修改测试套件的程序。 在最初的实现中,只支持 unittest 框架。我现在正在尝试添加对 Pytest 的支持。 使用默认的 unitest 模块,我可以将修改后的测试作为 AST 保
我有一个带有两种不同方法的单元测试测试用例。如果第一个方法失败,我希望跳过我的第二个方法。 我正在使用装饰器 @unittest.skipIf 但我找不到合适的条件。 class myTest(uni
根据文档,我可以在调用 unittest.main 时设置 python unittest 的详细级别,例如 unittest.main(verbosity=2) 如何在 unittest.TestC
有没有人遇到过这样的情况,他们将自己代码的单元测试写到一个名为unittest.py的文件中,发现它与NumPy的unittest.py模块冲突?换句话说,如果我将其写入本地目录中的 unittest
似乎有两种使用方式 unittest.mock.patch : 有更好的方法吗? 使用上下文管理器和 with 语句: class MyTest(TestCase): def test_som
在装有 PyCharm 的两台不同机器上,我有相同的项目。我有简单的代码: import unittest from tests import test unittest.makeSuite(test
我正在尝试执行我的以下测试套件: import unittest from Login_Page import LoginPageAndLogout def test_suite(): # g
当我正常运行应用程序并在浏览器中登录时,它可以正常工作。但是使用 Unittest 它不会让我登录....,它会再次返回登录页面。 “print rv.data”都只是打印登录页面的内容,但它应该打印
我仍在使用 Django 1.2.1,我认为对于较新的 Django,我们不会 import unittest然后做unittest.TestCase . 插图 import unittest cla
基于上一篇文章,这篇文章是关于使用coverage来实现代码覆盖的操作实例,源代码在上一篇已经给出相应链接。 本篇文章字用来实现代码覆盖的源代码,整个项目的测试框架如下: 就是在源代码的基础
当被测试的模块需要导入其他模块时,我们的 Python 3.10 单元测试会中断。当我们使用其他帖子和文章推荐的打包技术时,要么单元测试导入模块失败,要么直接调用运行应用程序导入模块失败。我们读过的其
我已经定义了一个自定义错误,但是如果我测试是否得到了自定义错误 提出来,它失败了。 我的models.py: class CustomError(Exception): """ Thi
我目前正在做一个项目,其结构是: my_package │ README.md | setup.py │ └───my_package | | __init__.py │ │
这是我的项目设置: my_project ./my_project ./__init__.py ./foo ./__init__
我是一名优秀的程序员,十分优秀!