<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
想要使用多個CPU核心來進行測試,可以使用 -n 引數( 或者 --numprocesses)
(使用8個核心來跑測試用例)
pytest -n 8
使用 -n auto
引數可以利用電腦的所有核心來跑測試用例
測試時使用的演演算法可以根據--dist
命令引數客製化:
--dist load
(預設選項):給每個CPU核心隨機分配用例,不保證執行順序。--dist loadscope
:對於測試函數,測試按模組分組,對於測試方法,測試按類分組。每組作為一個整體分配給可用的worker。這保證了組中的所有測試都在同一程序中執行。如果的模組級或類級fixtures,這將非常有用。按類分組優先於按模組分組。--dist loadfile
: 測試用例按其所在檔案分組。每組作為一個整體分配給可用的worker。這保證了檔案中的所有測試都在同一個輔助程序中執行。--dist loadgroup
: 測試按xdist_group標記分組。每組作為一個整體分配給可用的執行器。這保證了具有相同xdist_ group名稱的所有測試都在同一個worker中執行。@pytest.mark.xdist_group(name="group1") def test1(): pass class TestA: @pytest.mark.xdist_group("group1") def test2(): pass-
這將確保test1和TestA::test2將在同一個worker中執行。沒有xdist_ group標記的測試在--dist=load模式下正常執行。
--dist no
:正常的pytest執行模式,一次執行一個測試(完全沒有分發)。例子:
專案目錄結構
xdist_test.py
import logging import pytest class TestXdist(object): @pytest.mark.xdist_group("group1") def test_one(self): logging.info("1") assert True @pytest.mark.xdist_group("group1") def test_two(self): logging.info("2") assert True @pytest.mark.xdist_group("group2") def test_three(self): logging.info("3") assert True @pytest.mark.xdist_group("group2") def test_four(self): logging.info("4") assert True
xdist_dummy_test.py
import logging import pytest class TestXdist(object): @pytest.mark.run(order=1) @pytest.mark.xdist_group("group1") def test_dummy_one(self): logging.info("d1") assert True @pytest.mark.xdist_group("group1") @pytest.mark.run(order=2) def test_dummy_two(self): logging.info("d2") assert True @pytest.mark.run(order=3) @pytest.mark.xdist_group("group2") def test_dummy_three(self): logging.info("d3") assert True @pytest.mark.xdist_group("group2") @pytest.mark.run(order=4) def test_dummy_four(self): logging.info("d4") assert True
(venv) ➜ pytest pytest -n auto --dist loadscope =========================================================================== test session starts =========================================================================== platform darwin -- Python 3.8.9, pytest-7.1.2, pluggy-1.0.0 rootdir: /Users/spock/PycharmProjects/pytest, configfile: pytest.ini plugins: xdist-2.5.0, forked-1.4.0, ordering-0.6 [gw0] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw1] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw2] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw3] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw4] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw5] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw6] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw7] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] gw0 [8] / gw1 [8] / gw2 [8] / gw3 [8] / gw4 [8] / gw5 [8] / gw6 [8] / gw7 [8] scheduling tests via LoadScopeScheduling test2/xdist_dummy_test.py::TestXdist::test_dummy_one test/xdist_test.py::TestXdist::test_one [gw0] [ 12%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_one [gw1] [ 25%] PASSED test/xdist_test.py::TestXdist::test_one test2/xdist_dummy_test.py::TestXdist::test_dummy_two test/xdist_test.py::TestXdist::test_two [gw1] [ 37%] PASSED test/xdist_test.py::TestXdist::test_two test/xdist_test.py::TestXdist::test_three [gw0] [ 50%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_two test2/xdist_dummy_test.py::TestXdist::test_dummy_three [gw1] [ 62%] PASSED test/xdist_test.py::TestXdist::test_three test/xdist_test.py::TestXdist::test_four [gw0] [ 75%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_three test2/xdist_dummy_test.py::TestXdist::test_dummy_four [gw1] [ 87%] PASSED test/xdist_test.py::TestXdist::test_four [gw0] [100%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_four ============================================================================ 8 passed in 0.40s ============================================================================
(venv) ➜ pytest pytest -n auto --dist loadfile =========================================================================== test session starts =========================================================================== platform darwin -- Python 3.8.9, pytest-7.1.2, pluggy-1.0.0 rootdir: /Users/spock/PycharmProjects/pytest, configfile: pytest.ini plugins: xdist-2.5.0, forked-1.4.0, ordering-0.6 [gw0] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw1] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw2] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw3] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw4] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw5] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw6] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw7] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] gw0 [8] / gw1 [8] / gw2 [8] / gw3 [8] / gw4 [8] / gw5 [8] / gw6 [8] / gw7 [8] scheduling tests via LoadFileScheduling test/xdist_test.py::TestXdist::test_one test2/xdist_dummy_test.py::TestXdist::test_dummy_one [gw1] [ 12%] PASSED test/xdist_test.py::TestXdist::test_one [gw0] [ 25%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_one test/xdist_test.py::TestXdist::test_two test2/xdist_dummy_test.py::TestXdist::test_dummy_two [gw1] [ 37%] PASSED test/xdist_test.py::TestXdist::test_two [gw0] [ 50%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_two test2/xdist_dummy_test.py::TestXdist::test_dummy_three test/xdist_test.py::TestXdist::test_three [gw1] [ 62%] PASSED test/xdist_test.py::TestXdist::test_three [gw0] [ 75%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_three test2/xdist_dummy_test.py::TestXdist::test_dummy_four test/xdist_test.py::TestXdist::test_four [gw1] [ 87%] PASSED test/xdist_test.py::TestXdist::test_four [gw0] [100%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_four ============================================================================ 8 passed in 0.38s ============================================================================
(venv) ➜ pytest pytest -n auto --dist loadgroup =========================================================================== test session starts =========================================================================== platform darwin -- Python 3.8.9, pytest-7.1.2, pluggy-1.0.0 rootdir: /Users/spock/PycharmProjects/pytest, configfile: pytest.ini plugins: xdist-2.5.0, forked-1.4.0, ordering-0.6 [gw0] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw1] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw2] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw3] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw4] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw5] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw6] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] [gw7] Python 3.8.9 (default, May 17 2022, 12:55:41) -- [Clang 13.1.6 (clang-1316.0.21.2.5)] gw0 [8] / gw1 [8] / gw2 [8] / gw3 [8] / gw4 [8] / gw5 [8] / gw6 [8] / gw7 [8] scheduling tests via LoadGroupScheduling test2/xdist_dummy_test.py::TestXdist::test_dummy_three@group2 test2/xdist_dummy_test.py::TestXdist::test_dummy_one@group1 [gw1] [ 12%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_three@group2 test2/xdist_dummy_test.py::TestXdist::test_dummy_four@group2 [gw0] [ 25%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_one@group1 [gw1] [ 37%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_four@group2 test2/xdist_dummy_test.py::TestXdist::test_dummy_two@group1 [gw0] [ 50%] PASSED test2/xdist_dummy_test.py::TestXdist::test_dummy_two@group1 test/xdist_test.py::TestXdist::test_three@group2 [gw1] [ 62%] PASSED test/xdist_test.py::TestXdist::test_three@group2 test/xdist_test.py::TestXdist::test_four@group2 [gw1] [ 75%] PASSED test/xdist_test.py::TestXdist::test_four@group2 test/xdist_test.py::TestXdist::test_one@group1 [gw0] [ 87%] PASSED test/xdist_test.py::TestXdist::test_one@group1 test/xdist_test.py::TestXdist::test_two@group1 [gw0] [100%] PASSED test/xdist_test.py::TestXdist::test_two@group1 ============================================================================ 8 passed in 0.40s ============================================================================
到此這篇關於pytest分散式執行外掛 pytest-xdist 的高階用法的文章就介紹到這了,更多相關pytest分散式執行外掛 pytest-xdist內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45