如何解决通过 pytest xdist 在 python selenium 中并行运行时测试失败,但按顺序运行良好
当我用
运行下面的代码时pytest .\tests\GET\test_setupFunc.py
完美运行 即 setup(my_fixture) 函数运行一次,然后 test_one 和 test_two
如果我使用pytest-xdist并行运行它
pytest .\tests\GET\test_setupFunc.py -n=2
失败
我认为 my_fixture 正在被两个测试调用,因为我已经设置了 scope="session"
该函数应该被共享。
一旦该函数成功运行,我希望并行性应该被触发
==========简短的测试摘要信息 ==========
ERROR tests\GET\test_setupFunc.py::test_one - selenium.common.exceptions.WebDriverException:消息:未知错误: 无法删除旧的 devtools 端口文件。 也许 t...
如果您打算运行它,请在添加参数代码步骤中将 yourusername 替换为您的系统用户名
'''
import pytest
import logging
logging.basicConfig(format='%(message)s')
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
@pytest.fixture(autouse=True,scope='session')
def my_fixture():
logging.warning('setup function')
print(" i will be called only once i am one time")
options = webdriver.ChromeOptions()
options.add_argument('--profile-directory=Default')
options.add_argument("--user-data-dir=c:\\Users\\yourUserName\\AppData\\Local\\Google\\Chrome\\User Data")
driver=webdriver.Chrome(ChromeDriverManager().install(),options=options)
driver.get("https://gmail.com")
driver.quit()
def test_one():
logging.warning('test_a')
print(" i am first function")
def test_two():
logging.warning('test_b')
print(" i am second function")
还要注意,如果我删除了 selenium
相关步骤并只保留打印语句,它可以正常工作
预期结果
pytest-parallel
不支持 python 3.9 但也尝试过
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。