我有以下通过 py.test 运行的单元测试代码。
构造函数的存在会使整个类在运行时跳过
py.test-v-s
已收集 0 件 / 已跳过 1 件
谁能向我解释 py.test 的这种行为吗?
我有兴趣了解 py.test 行为,我知道不需要构造函数。
谢谢,
兹代内克
class TestClassName(object):
def __init__(self):
pass
def setup_method(self, method):
print "setup_method called"
def teardown_method(self, method):
print "teardown_method called"
def test_a(self):
print "test_a called"
assert 1 == 1
def test_b(self):
print "test_b called"
assert 1 == 1
py.test 的文档says http://doc.pytest.org/en/latest/goodpractices.html#conventions-for-python-test-discoverypy.test 实现以下标准测试发现:
- 集合从初始命令行参数开始,这些参数可能是目录、文件名或测试 ID。
递归到目录,除非它们与 norecursedirs 匹配
- test_*.py 或 *_test.py 文件,按包名称导入。
-
Test
带前缀的测试类(没有__init__
方法) []
-
test_
带前缀的测试函数或方法是测试项
所以并不是不需要构造函数, py.test 只是忽略了以下类have一个构造函数。还有一个guide http://doc.pytest.org/en/latest/example/pythoncollection.html用于更改标准测试发现。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)