【发布时间】:2014-06-28 01:20:04
【问题描述】:
IDE: PyCharm 社区版 3.1.1
Python: 2.7.6
我使用 DDT 进行测试参数化http://ddt.readthedocs.org/en/latest/example.html
我想从 PyCharm 的测试类中选择并运行参数化测试方法 -> 参见示例:
from unittest import TestCase
from ddt import ddt, data
@ddt
class Test_parameterized(TestCase):
def test_print_value(self):
print 10
self.assertIsNotNone(10)
@data(10, 20, 30, 40)
def test_print_value_parametrized(self, value):
print value
self.assertIsNotNone(value)
当我导航到代码中的第一个测试方法 test_print_value 并点击 ctrl+Shift+F10 (或使用 Run Unittest test_print...上下文菜单中的选项)
然后执行测试。
当我对参数化测试进行同样的尝试时,我得到了错误:
Test framework quit unexpectedly
输出包含:
/usr/bin/python2 /home/s/App/pycharm-community-3.1.1/helpers/pycharm/utrunner.py
/home/s/Documents/Py/first/fib/test_parametrized.py::Test_parameterized::test_print_value_parametrized true
Testing started at 10:35 AM ...
Traceback (most recent call last):
File "/home/s/App/pycharm-community-3.1.1/helpers/pycharm/utrunner.py", line 148, in <module>
testLoader.makeTest(getattr(testCaseClass, a[2]), testCaseClass))
AttributeError: 'TestLoader' object has no attribute 'makeTest'
Process finished with exit code 1
但是,当我在类中运行所有测试(通过导航到代码中的测试类名称并使用提到的运行测试选项)时,所有参数化和非参数化测试都会一起执行而不会出错。
问题是如何从测试类独立运行参数化方法 - 解决方法是为每个测试类放置一个参数化测试,但这是一个相当混乱的解决方案。
【问题讨论】:
标签: python unit-testing python-2.7 pycharm parameterized