Pytest运行指定的case
在测试工作中,当我们写了较多的cases时,如果每次都要全部运行一遍,无疑是很浪费时间的,而且效率低下。
但是有一种方法可以帮助你快速地运行指定的测试用例,提高测试效率,那就是使用Pytest来运行指定的case!这种方法不仅可以节省时间,而且能够准确地测试出特定的功能和模块。
赶紧来试一试,相信你会很快感受到它的高效和便捷!
例子代码:
test_aa.py
class TestClassOne(object):def test_one(self):x = "this"assert 't'in xdef test_two(self):x = "hello"assert hasattr(x, 'check')class TestClassTwo(object):def test_one(self):x = "iphone"assert 'p'in xdef test_two(self):x = "apple"assert hasattr(x, 'check')
运行模式:
模式1:直接运行test_aa.py文件中的所有cases:
pytest test_aa.py
模式2:运行test_aa.py文件中的TestClassOne这个class下的两个cases:
pytest test_aa.py::TestClassOne
模式3:运行test_aa.py文件中的TestClassTwo这个class下的test_one:
pytest test_aa.py::TestClassTwo::test_one
注意:定义class时,需要以T开头,不然pytest是不会去运行该class的。
B站讲的最详细的pytest教程,快速入门精选pytest实战教程!!
【留言:录播教程,即可免费获取】