使用pytest

2018-08-06  本文已影响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
上一篇 下一篇

猜你喜欢

热点阅读