Python 3.x 并行运行测试时,仅运行pytest夹具一次

Python 3.x 并行运行测试时,仅运行pytest夹具一次,python-3.x,pytest,fixtures,parallel-testing,pytest-xdist,Python 3.x,Pytest,Fixtures,Parallel Testing,Pytest Xdist,当测试通过shell脚本并行运行时,我在conftest文件中只运行一次pytest fixture时遇到了一些实际困难。shell脚本的内容如下: #!/usr/bin/env bash pytest -k 'mobile' --os iphone my_tests/ & pytest -k 'mobile' --os ipad my_tests/ wait pytest fixture在运行测试之前为移动设备测试创建要使用的资源: @pytest.fixture(scope='se

当测试通过shell脚本并行运行时,我在conftest文件中只运行一次pytest fixture时遇到了一些实际困难。shell脚本的内容如下:

#!/usr/bin/env bash
pytest -k 'mobile' --os iphone my_tests/ &
pytest -k 'mobile' --os ipad my_tests/
wait
pytest fixture在运行测试之前为移动设备测试创建要使用的资源:

@pytest.fixture(scope='session', autouse=True)
def create_resources():
    // Do stuff to create the resources
    yield
    // Do stuff to remove the resources
当单独运行每一个时,它工作得非常完美。创建资源,运行测试,最后删除它创建的资源。当并行运行(使用shell脚本)时,两者都尝试同时运行create_resources fixture


有人知道我可以只运行一次create_资源装置的方法吗?如果是这样,那么第二台设备是否可以等到创建资源后再运行测试?

您可以使用某种文件锁,例如,尝试在安装前以独占模式创建一个锁定文件,并在关机时将其删除-您还需要一些等待方法来检测安装程序是否复杂,以便能够等待。您可以使用某种文件锁定,例如,尝试在安装前以独占模式创建一个锁文件,并在关机时将其删除-您还需要一些等待方法来检测安装是否复杂,以便能够等待它。