pytest学习(2)
2017-07-20 19:43 很大很老实 阅读(823) 评论(0) 收藏 举报可以把多个test放在一个class里,
class TestClass(object):
def test_one(self):
x = "this"
assert 'h' in x
def test_two(self):
x = "hello"
assert hasattr(x, 'check')
为什么会找到呢,因为,在pytest的文档里,说明查找的规范思路:
pytest implements the following standard test discovery:
- If no arguments are specified then collection starts from
testpaths(if configured) or the current directory. Alternatively, command line arguments can be used in any combination of directories, file names or node ids. - Recurse into directories, unless they match
norecursedirs. - In those directories, search for
test_*.pyor*_test.pyfiles, imported by their test package name. - From those files, collect test items:
test_prefixed test functions or methods outside of classtest_prefixed test functions or methods insideTestprefixed test classes (without an__init__method)
For examples of how to customize your test discovery Changing standard (Python) test discovery.
Within Python modules, pytest also discovers tests using the standard unittest.TestCasesubclassing technique.
这里需要注意的是,这个类不能有__init__
浙公网安备 33010602011771号