py.test在类下没有找到测试

时间:2013-11-29 01:27:20

标签: python unit-testing pycharm pytest

我正在尝试创建非基于单元测试的测试类。

此类

下的此方法
class ClassUnderTestTests:

    def test_something(self):
当您从命令行调用py.test或在PyCharm中运行此测试时(在它自己的模块上),

无法检测并运行。

def test_something(self):

可以检测并运行类外的相同方法。

我想在课堂上分组我的测试,除非我遗漏了一些我正在跟踪py.test spec的事情。

环境:Windows 7,py.harc,py.test设置为测试运行器。

1 个答案:

答案 0 :(得分:26)

按惯例,它会搜索

  

测试前缀测试类(没有 init 方法)

例如

# 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')

查看文档here

相关问题