我最近开始使用pytest运行我的自动化测试套件。依次运行时成功完成的测试运行,现在当我使用xdist并行运行套件时随机失败。我将pytest配置如下:
[pytest]
addopts = -nauto --rerun 3 -ra --timeout=180 --junit-xml=pyresult.xml
python_files=test*.py
Run Code Online (Sandbox Code Playgroud)
随机测试将无法启动Chromedriver,并且最终将引发超时。对于其他由于种种原因失败的测试失败的情况,pytest会很乐意为我重新运行测试。但是在这种情况下,当抛出超时时,pytest输出超时然后挂起。我的测试运行永远不会结束,因此詹金斯没有得到等待的结果。完成pytest的唯一方法是手动发送控制中断。
我的驱动程序如下启动(注意,我认为我的代码不是这里的问题);
@classmethod
def open_browser(cls, browser_name, configuration, down_dir=""):
"""
Returns the driver for the required browser
"""
if browser_name == 'Chrome':
chrome_options = webdriver.ChromeOptions()
prefs = {"download.default_directory" : down_dir}
chrome_options.add_experimental_option("prefs", prefs)
driver = webdriver.Chrome(
executable_path=configuration, chrome_options=chrome_options)
Run Code Online (Sandbox Code Playgroud)
超时消息如下:
~~~~~~~~~~~~~~~~~~~~~~~~~~ Stack of <unknown> (8460) ~~~~~~~~~~~~~~~~~~~~~~~~~~~
File "c:\python27\lib\site-packages\execnet\gateway_base.py", line 277, in _perform_spawn
reply.run()
File "c:\python27\lib\site-packages\execnet\gateway_base.py", line 213, in run
self._result = func(*args, **kwargs)
File "c:\python27\lib\site-packages\execnet\gateway_base.py", line 954, in _thread_receiver
msg = Message.from_io(io) …Run Code Online (Sandbox Code Playgroud)