Pytest绯诲垪锛?8锛? 瓒呯編娴嬭瘯鎶ュ憡鎻掍欢涔媋llure-pytest鐨勫熀纭€浣跨敤
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Pytest绯诲垪锛?8锛? 瓒呯編娴嬭瘯鎶ュ憡鎻掍欢涔媋llure-pytest鐨勫熀纭€浣跨敤相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e6%96%87%e4%bb%b6' title='鏂囦欢'>鏂囦欢 www ext nts 璺熻釜 over view
濡傛灉浣犺繕鎯充粠澶村璧稰ytest锛屽彲浠ョ湅鐪嬭繖涓郴鍒楃殑鏂囩珷鍝︼紒
https://www.cnblogs.com/poloyy/category/1690628.html
瀹樻柟浠嬬粛
- Allure Framework鏄竴绉嶇伒娲荤殑杞婚噺绾у璇█娴嬭瘯鎶ュ憡宸ュ叿锛屼笉浠呭彲浠ヤ互绠€娲佺殑Web鎶ュ憡褰㈠紡闈炲父绠€娲佸湴鏄剧ず宸叉祴璇曠殑鍐呭锛屼篃鍏佽鍙備笌寮€鍙戣繃绋嬬殑姣忎釜浜轰粠鏃ュ父娴嬭瘯涓彁鍙栨渶澶х▼搴︾殑鏈夌敤淇℃伅
- 浠庡紑鍙?璐ㄩ噺淇濊瘉鐨勮搴︽潵鐪嬶紝Allure鎶ュ憡鍙互缂╃煭甯歌缂洪櫡鐨勭敓鍛藉懆鏈燂細鍙互灏嗘祴璇曞け璐ュ垝鍒嗕负bug鍜屾崯鍧忕殑娴嬭瘯锛岃繕鍙互閰嶇疆log锛宻tep锛宖ixture锛宎ttachments锛宼imings锛屽巻鍙茶褰曚互鍙婁笌TMS鐨勯泦鎴愪互鍙夿ug璺熻釜绯荤粺锛屽洜姝よ礋璐d换鐨勫紑鍙戜汉鍛樺拰娴嬭瘯浜哄憳灏嗘帉鎻℃墍鏈変俊鎭?/li>
- 浠庣鐞嗕汉鍛樼殑瑙掑害鏉ョ湅锛孉llure鎻愪緵浜嗕竴涓竻鏅扮殑“鍏ㄥ眬”锛屾兜鐩栦簡宸叉兜鐩栫殑鍔熻兘锛岀己闄疯仛闆嗙殑浣嶇疆锛屾墽琛屾椂闂磋〃鐨勫瑙備互鍙婅澶氬叾浠栨柟渚跨殑浜嬫儏
- Allure鐨勬ā鍧楀寲鍜屽彲鎵╁睍鎬х‘淇濇偍濮嬬粓鑳藉寰皟鏌愪簺涓滆タ锛屼互浣緼llure鏇撮€傚悎鎮?/li>
涓汉浠嬬粛
- 瀵逛簬绠$悊灞傛潵璇达紝娴嬭瘯鎶ュ憡褰撶劧鏄秺鐩磋銆佺畝娲併€佹暟鎹竻鏅拌秺濂斤紝鑰孉llure灏辨弧瓒充互涓婅繖涔堝鐐癸紝鑰屼笖寰堝ソ鐨勫拰pytest闆嗘垚浜?/li>
- 鐩告瘮浜巔ytest-html鏉ヨ锛孉llure鐨勬姤鍛婄湡鐨勬槸鍗佸叏鍗佺編楦紒锛?/li>
- 鍞竴涓嶈冻鐨勫氨鏄紝鎷撳睍鍔熻兘闇€瑕佸湪娴嬭瘯鐢ㄤ緥闆嗕笂鍔犺楗板櫒
瀹夎鎻掍欢
pip3 install allure-pytest -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
蹇€熷叆闂?/h2>
杩欐槸杩愯浠g爜鐨勫寘缁撴瀯
# 鏄」鐩枃浠跺す鍚嶇О 15allure 鈹? conftest.py 鈹? test_1.py 鈹? __init__.py 鈹? 鈹溾攢test_51job 鈹? 鈹? conftest.py 鈹? 鈹? test_case1.py 鈹? 鈹? __init__.py 鈹? 鈹溾攢test_toutiao 鈹? 鈹? test_case2.py 鈹?鈹溾攢test_weibo 鈹? 鈹? conftest.py 鈹? 鈹? test_case3.py 鈹? 鈹? __init__.py 鈹?
鏈€澶栧眰鐨刢onftest.py
# 澶栧眰conftest.py @pytest.fixture(scope="session") def login(): print("====鐧诲綍鍔熻兘锛岃繑鍥炶处鍙凤紝token===") name = "testyy" token = "npoi213bn4" yield name, token print("====閫€鍑虹櫥褰曪紒锛侊紒====")
鏈€澶栧眰鐨則est_1.py
import pytest @pytest.mark.parametrize("n", list(range(5))) def test_get_info(login, n): sleep(1) name, token = login print("***鍩虹鐢ㄤ緥锛氳幏鍙栫敤鎴蜂釜浜轰俊鎭?**", n) print(f"鐢ㄦ埛鍚?{name}, token:{token}")
test_51job鍖呬笅鐨刢onftest.py
import pytest @pytest.fixture(scope="module") def open_51(login): name, token = login print(f"###鐢ㄦ埛 {name} 鎵撳紑51job缃戠珯###")
test_51job鍖呬笅鐨則est_case1.py
from time import sleep import pytest @pytest.mark.parametrize("n", list(range(5))) def test_case2_01(open_51, n): sleep(1) print("51job锛屽垪鍑烘墍鏈夎亴浣嶇敤渚?/span>", n) @pytest.mark.parametrize("n", list(range(5))) def test_case2_02(open_51, n): sleep(1) print("51job锛屾壘鍑烘墍鏈塸ython宀椾綅", n)
test_toutiao鍖呬笅鐨則est_case2.py
from time import sleep import pytest @pytest.mark.parametrize("n", list(range(5))) def test_no_fixture(login, n): sleep(1) print("==娌℃湁__init__娴嬭瘯鐢ㄤ緥锛屾垜杩涘叆澶存潯浜?=", login)
test_weibo鍖呬笅鐨刢onftest.py
import pytest @pytest.fixture(scope="function") def open_weibo(login): name, token = login print(f"&&& 鐢ㄦ埛 {name} 杩斿洖寰崥棣栭〉 &&&")
test_weibo鍖呬笅鐨則est_case3.py
from time import sleep import pytest @pytest.mark.parametrize("n", list(range(5))) class TestWeibo: def test_case1_01(self, open_weibo, n): sleep(1) print("鏌ョ湅寰崥鐑悳", n) def test_case1_02(self, open_weibo, n): sleep(1) print("鏌ョ湅寰崥鑼冨啺鍐?/span>", n)
鎵ц鍛戒护
瑕佷娇Allure鑳藉鍦ㄦ祴璇曟墽琛屾湡闂存敹闆嗘祴璇曠粨鏋滐紝鍙渶娣诲姞 --alluredir 閫夐」锛屽苟鎻愪緵鎸囧悜搴斿瓨鍌ㄧ粨鏋滅殑鏂囦欢澶圭殑璺緞
pytest -n auto --alluredir=allure
鐢熸垚鍑烘潵鐨勭粨鏋?/h3>
鍙互鐪嬪埌锛岃繖涓嶆槸鎴戜滑鎯宠鐨勭粨鏋滐紝涓€鍫唈son銆乼xt鏂囦欢....
瑕佸湪娴嬭瘯瀹屾垚鍚庢煡鐪嬪疄闄呮姤鍛婏紝闇€瑕佷娇鐢ˋllure鍛戒护琛屾潵璁╂祴璇曠粨鏋滅敓鎴愭姤鍛?/span>
allure serve allure
鐒跺悗灏变細鑷姩鍦ㄩ粯璁ゆ祻瑙堝櫒涓樉绀虹敓鎴愮殑鎶ュ憡
鏌ョ湅suites锛堝嚱鏁扮骇鍒殑娴嬭瘯鐢ㄤ緥锛?/h2>
浠庡寘鍚?妯″潡鍚?娴嬭瘯鐢ㄤ緥
鏌ョ湅suites锛堢被绾у埆鐨勬祴璇曠敤渚嬶級
浠庡寘鍚?妯″潡鍚?绫诲悕-娴嬭瘯鐢ㄤ緥
鏌ョ湅娴嬭瘯鐢ㄤ緥璇︽儏
- parameters锛氬鏋滅敤浜?nbsp;@pytest.mark.parametrize 锛屽湪鍙充晶鐨刾arameters鏄彲浠ョ湅鍒颁紶浜嗕粈涔堝弬鏁板拰瀵瑰簲鐨勫€?/li>
- set up锛氳皟鐢╢ixture鐨勫墠缃搷浣?/li>
- tear down锛氳皟鐢╢ixture鐨勫悗缃搷浣溿€€