我正在尝试创建不基于单元测试的测试类。
这个类下的这个方法
class ClassUnderTestTests:
def test_something(self):
当您从命令行调用 py.test 或在 PyCharm 中运行此测试时(它在自己的模块上)时,无法检测和运行。
这个
def test_something(self):
可以检测并运行类外的相同方法。
我想将我的测试归类,除非我遗漏了什么,否则我会关注 py.test spec这样做。
环境:Windows 7,将 py.test 设置为测试运行器的 PyCharm。
最佳答案
按照惯例,它会搜索
Test prefixed test classes (without an init method)
例如。
# content of test_class.py
class TestClass:
def test_one(self):
x = "this"
assert 'h' in x
def test_two(self):
x = "hello"
assert hasattr(x, 'check')
# this works too
@staticmethod
def test_three():
pass
# this doesn't work
#@classmethod
#def test_three(cls):
# pass
查看文档:
关于python - py.test 在类下找不到测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20277058/