pytest运行多个测试类
1.python终端执行pip install pytest-xdist
2.创建conftest.py(pytest默认读取conftest.py里面的配置)
import pytest
from selenium import webdriver
@pytest.fixture(scope="session")
def setup(request):
print("initiating chrome driver")
driver = webdriver.Chrome(r'C:/Users/MNN/AppData/Local/Google/Chrome/Application/chromedriver.exe')
session = request.node
for item in session.items:
cls = item.getparent(pytest.Class)
setattr(cls.obj, "driver", driver)
driver.get("http://www.baidu.com")
driver.maximize_window()
yield driver
driver.close()
3.创建test_example1.py
import pytest
@pytest.mark.usefixtures("setup")
class TestExampleOne:
def test_title(self):
assert "百度一下,你就知道" in self.driver.title
4.创建test_example2.py
import pytest
import time
@pytest.mark.usefixtures("setup")
class TestExampleTwo:
def test_InputForm(self):
print("Another example")
mainMenu = self.driver.find_element_by_xpath("//a[contains(text(),'新闻')]")
print(mainMenu.text)
assert "新闻" in mainMenu.text
def test_funcfast(self):
time.sleep(0.1)
def test_funcslow1(self):
time.sleep(0.2)
def test_funcslow2(self):
time.sleep(0.3)
5.在pycharm终端执行命令:pytest -s -v -n=2
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。