首页 文章

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

提问于
浏览
14

我正在尝试创建不基于单元测试的测试类 .

这个类下的这个方法

class ClassUnderTestTests:

    def test_something(self):

从命令行调用py.test或在PyCharm中运行此测试时(在它自己的模块上),无法检测并运行 .

这个

def test_something(self):

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

我错过了一些我正在追踪py.test spec的事情 .

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

1 回答

  • 24

    按照惯例,它会搜索

    测试前缀测试类(没有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

相关问题