如何正确使用pytest的装饰器pytest.mark.usefixtures?
- 内容介绍
- 文章标签
- 相关推荐
本文共计609个文字,预计阅读时间需要3分钟。
在之前的学习中,代码中直接导入了fixture函数common_driver,并通过pytest的装饰器usefixtures来使用。具体实现如下:python@ pytest.mark.usefixtures(common_driver)def test_welcome(self, common_driver): WelcomePage(common_driver).swipe_screen()
在之前的学习中,代码中一直是传入了fixture函数common_driver,又使用了pytest.mark.usefixtures:
@pytest.mark.usefixtures("common_driver")def test_welcome(self, common_driver):
WelcomePage(common_driver).swipe_screen()
WelcomePage(common_driver).get_spe_screenshot()
image_text = WelcomePage(common_driver).identify_screenshot()
assert image_text == "立即体验"
今天看pytest官方文档,发现可以不这么用,主要分为两种情况
1. 当不需要使用fixture中的返回时,直接使用pytest.mark.usefixtures(funcname)。
本文共计609个文字,预计阅读时间需要3分钟。
在之前的学习中,代码中直接导入了fixture函数common_driver,并通过pytest的装饰器usefixtures来使用。具体实现如下:python@ pytest.mark.usefixtures(common_driver)def test_welcome(self, common_driver): WelcomePage(common_driver).swipe_screen()
在之前的学习中,代码中一直是传入了fixture函数common_driver,又使用了pytest.mark.usefixtures:
@pytest.mark.usefixtures("common_driver")def test_welcome(self, common_driver):
WelcomePage(common_driver).swipe_screen()
WelcomePage(common_driver).get_spe_screenshot()
image_text = WelcomePage(common_driver).identify_screenshot()
assert image_text == "立即体验"
今天看pytest官方文档,发现可以不这么用,主要分为两种情况
1. 当不需要使用fixture中的返回时,直接使用pytest.mark.usefixtures(funcname)。

