Pytest运行指定的case
在测试工作中,当我们写了较多的cases时,如果每次都要全部运行一遍,无疑是很浪费时间的,而且效率低下。
但是有一种方法可以帮助你快速地运行指定的测试用例,提高测试效率,那就是使用Pytest来运行指定的case!这种方法不仅可以节省时间,而且能够准确地测试出特定的功能和模块。
赶紧来试一试,相信你会很快感受到它的高效和便捷!
例子代码:
test_aa.py
class TestClassOne(object):
def test_one(self):
x = "this"
assert 't'in x
def test_two(self):
x = "hello"
assert hasattr(x, 'check')
class TestClassTwo(object):
def test_one(self):
x = "iphone"
assert 'p'in x
def 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的。
感谢每一个认真阅读我文章的人,礼尚往来总是要有的,虽然不是什么很值钱的东西,如果你用得到的话可以直接拿走:
这些资料,对于【软件测试】的朋友来说应该是最全面最完整的备战仓库,这个仓库也陪伴上万个测试工程师们走过最艰难的路程,希望也能帮助到你!有需要的小伙伴可以点击下方小卡片领取