美文网首页
使用pytest

使用pytest

作者: 唯此 | 来源:发表于2018-08-06 00:28 被阅读0次

配置项目默认使用pytest

image.png run config

这里配置的-s参数是让print函数能够正常打印出啦.

编写测试用例

编写pytest测试样例非常简单,不需要继承TestCase类.只需要按照下面的规则:
测试文件以test_开头(以test结尾也可以)
测试类以Test开头,并且不能带有 init 方法
测试函数以test
开头
断言使用基本的assert即可

# content of test_class.py
class TestClass:
    def test_one(self):
        x = "this"
        assert 'h' in x

    def test_two(self):
        x = "hello"
        assert x == 'check'

运行测试用例.

如果右击TestClass,然后点击运行,会运行这个类下面的所有测试用例.

运行TestClass

如果右击test_one然后点击运行,只会运行这个函数.

运行test_one

相关文章

网友评论

      本文标题:使用pytest

      本文链接:https://www.haomeiwen.com/subject/lmtsvftx.html