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

 

瀹樻柟浠嬬粛

  1. Allure Framework鏄竴绉嶇伒娲荤殑杞婚噺绾у璇█娴嬭瘯鎶ュ憡宸ュ叿锛屼笉浠呭彲浠ヤ互绠€娲佺殑Web鎶ュ憡褰㈠紡闈炲父绠€娲佸湴鏄剧ず宸叉祴璇曠殑鍐呭锛屼篃鍏佽鍙備笌寮€鍙戣繃绋嬬殑姣忎釜浜轰粠鏃ュ父娴嬭瘯涓彁鍙栨渶澶х▼搴︾殑鏈夌敤淇℃伅
  2. 浠庡紑鍙?璐ㄩ噺淇濊瘉鐨勮搴︽潵鐪嬶紝Allure鎶ュ憡鍙互缂╃煭甯歌缂洪櫡鐨勭敓鍛藉懆鏈燂細鍙互灏嗘祴璇曞け璐ュ垝鍒嗕负bug鍜屾崯鍧忕殑娴嬭瘯锛岃繕鍙互閰嶇疆log锛宻tep锛宖ixture锛宎ttachments锛宼imings锛屽巻鍙茶褰曚互鍙婁笌TMS鐨勯泦鎴愪互鍙夿ug璺熻釜绯荤粺锛屽洜姝よ礋璐d换鐨勫紑鍙戜汉鍛樺拰娴嬭瘯浜哄憳灏嗘帉鎻℃墍鏈変俊鎭?/li>
  3. 浠庣鐞嗕汉鍛樼殑瑙掑害鏉ョ湅锛孉llure鎻愪緵浜嗕竴涓竻鏅扮殑“鍏ㄥ眬”锛屾兜鐩栦簡宸叉兜鐩栫殑鍔熻兘锛岀己闄疯仛闆嗙殑浣嶇疆锛屾墽琛屾椂闂磋〃鐨勫瑙備互鍙婅澶氬叾浠栨柟渚跨殑浜嬫儏
  4. Allure鐨勬ā鍧楀寲鍜屽彲鎵╁睍鎬х‘淇濇偍濮嬬粓鑳藉寰皟鏌愪簺涓滆タ锛屼互浣緼llure鏇撮€傚悎鎮?/li>

 

涓汉浠嬬粛

  1. 瀵逛簬绠$悊灞傛潵璇达紝娴嬭瘯鎶ュ憡褰撶劧鏄秺鐩磋銆佺畝娲併€佹暟鎹竻鏅拌秺濂斤紝鑰孉llure灏辨弧瓒充互涓婅繖涔堝鐐癸紝鑰屼笖寰堝ソ鐨勫拰pytest闆嗘垚浜?/li>
  2. 鐩告瘮浜巔ytest-html鏉ヨ锛孉llure鐨勬姤鍛婄湡鐨勬槸鍗佸叏鍗佺編楦紒锛?/li>
  3. 鍞竴涓嶈冻鐨勫氨鏄紝鎷撳睍鍔熻兘闇€瑕佸湪娴嬭瘯鐢ㄤ緥闆嗕笂鍔犺楗板櫒

 

瀹夎鎻掍欢

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

鎶€鏈浘鐗? id=
# 澶栧眰conftest.py

@pytest.fixture(scope="session")
def login():
    print("====鐧诲綍鍔熻兘锛岃繑鍥炶处鍙凤紝token===")
    name = "testyy"
    token = "npoi213bn4"
    yield name, token
    print("====閫€鍑虹櫥褰曪紒锛侊紒====")
View Code

 

鏈€澶栧眰鐨則est_1.py

鎶€鏈浘鐗? id=
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}")
View Code

 

test_51job鍖呬笅鐨刢onftest.py

鎶€鏈浘鐗? id=
import pytest


@pytest.fixture(scope="module")
def open_51(login):
    name, token = login
    print(f"###鐢ㄦ埛 {name} 鎵撳紑51job缃戠珯###")
View Code

 

test_51job鍖呬笅鐨則est_case1.py

鎶€鏈浘鐗? id=
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)
View Code

 

test_toutiao鍖呬笅鐨則est_case2.py

鎶€鏈浘鐗? id=
from time import sleep

import pytest


@pytest.mark.parametrize("n", list(range(5)))
def test_no_fixture(login, n):
    sleep(1)
    print("==娌℃湁__init__娴嬭瘯鐢ㄤ緥锛屾垜杩涘叆澶存潯浜?=", login)
View Code

 

test_weibo鍖呬笅鐨刢onftest.py

鎶€鏈浘鐗? id=
import pytest


@pytest.fixture(scope="function")
def open_weibo(login):
    name, token = login
    print(f"&&& 鐢ㄦ埛 {name} 杩斿洖寰崥棣栭〉 &&&")
View Code

 

test_weibo鍖呬笅鐨則est_case3.py

鎶€鏈浘鐗? id=
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)
View Code

 

鎵ц鍛戒护

瑕佷娇Allure鑳藉鍦ㄦ祴璇曟墽琛屾湡闂存敹闆嗘祴璇曠粨鏋滐紝鍙渶娣诲姞 --alluredir 閫夐」锛屽苟鎻愪緵鎸囧悜搴斿瓨鍌ㄧ粨鏋滅殑鏂囦欢澶圭殑璺緞

pytest -n auto --alluredir=allure

 

鐢熸垚鍑烘潵鐨勭粨鏋?/h3>

鍙互鐪嬪埌锛岃繖涓嶆槸鎴戜滑鎯宠鐨勭粨鏋滐紝涓€鍫唈son銆乼xt鏂囦欢....

鎶€鏈浘鐗? src=

 

瑕佸湪娴嬭瘯瀹屾垚鍚庢煡鐪嬪疄闄呮姤鍛婏紝闇€瑕佷娇鐢ˋllure鍛戒护琛屾潵璁╂祴璇曠粨鏋滅敓鎴愭姤鍛?/span>

allure serve allure

鐒跺悗灏变細鑷姩鍦ㄩ粯璁ゆ祻瑙堝櫒涓樉绀虹敓鎴愮殑鎶ュ憡

鎶€鏈浘鐗? src=

 

鏌ョ湅suites锛堝嚱鏁扮骇鍒殑娴嬭瘯鐢ㄤ緥锛?/h2>

浠庡寘鍚?妯″潡鍚?娴嬭瘯鐢ㄤ緥

鎶€鏈浘鐗? src=

 

鏌ョ湅suites锛堢被绾у埆鐨勬祴璇曠敤渚嬶級

浠庡寘鍚?妯″潡鍚?绫诲悕-娴嬭瘯鐢ㄤ緥

鎶€鏈浘鐗? src=

 

鏌ョ湅娴嬭瘯鐢ㄤ緥璇︽儏

  • parameters锛氬鏋滅敤浜?nbsp;@pytest.mark.parametrize 锛屽湪鍙充晶鐨刾arameters鏄彲浠ョ湅鍒颁紶浜嗕粈涔堝弬鏁板拰瀵瑰簲鐨勫€?/li>
  • set up锛氳皟鐢╢ixture鐨勫墠缃搷浣?/li>
  • tear down锛氳皟鐢╢ixture鐨勫悗缃搷浣溿€€

鎶€鏈浘鐗? src=

 

Allure鎶ュ憡缁撴瀯

  • Overview锛氭€昏
  • Categories锛氱被鍒紝榛樿鏄垎浜唂ailed鍜宔rror锛屽嚒鏄墽琛岀粨鏋滄槸鍏朵腑涓€涓殑閮戒細琚綊鍒扮被閲岄潰锛屽彲浠ラ€氳繃杩欓噷蹇嵎鏌ョ湅鍝簺鐢ㄤ緥鏄痜ailed鍜宔rror鐨?/div>
  • Suites锛氭祴璇曞浠讹紝灏辨槸鎵€鏈夌敤渚嬬殑灞傜骇鍏崇郴锛屽彲浠ユ牴鎹畃ackage銆乵odule銆佺被銆佹柟娉曟潵鏌ユ壘鐢ㄤ緥
  • Graphs锛氭祴璇曠粨鏋滃浘褰㈠寲锛屽寘鎷敤渚嬫墽琛岀粨鏋滅殑鍒嗗竷鍥撅紝浼樺厛绾э紝鑰楁椂绛?/div>
  • Timeline锛氬彲浠ョ湅鍒版祴璇曠敤渚嬬簿纭殑娴嬭瘯鏃跺簭锛堟墽琛岄『搴忥級锛屽寘鎷墽琛屾椂闂?/div>
  • Behaviors锛氳涓洪┍鍔紝鏍规嵁epic銆乫eature銆乻tory鏉ュ垎缁勬祴璇曠敤渚嬶紙鍚庨潰浼氳鍒帮級
  • Packages锛氳繖灏辨槸鎸夌収package銆乵odule鏉ュ垎缁勬祴璇曠敤渚嬩簡
 

 

以上是关于Pytest绯诲垪锛?8锛? 瓒呯編娴嬭瘯鎶ュ憡鎻掍欢涔媋llure-pytest鐨勫熀纭€浣跨敤的主要内容,如果未能解决你的问题,请参考以下文章

鏁欏コ鏈嬪弸璇绘噦绯诲垪锛歞ubbo鐨勫彲鎵╁睍鏈哄埗SPI 婧愮爜鍒嗘瀽

鏄撻敊鏄撴贩娣嗙煡璇嗙偣璁茶В绯诲垪锛堜節锛夆€斿缓绔嬪姩鎬佽鍒掓ā鍨嬬殑鍩烘湰姝ラ

妯℃嫙娴嬭瘯68锛?9

鏂版墜蹇呭锛屽ぇ鐗涙暣鐞嗙殑鎺ュ彛娴嬭瘯鐭ヨ瘑鐐规€荤粨

娣卞叆瀛︿範 Redis绯诲垪

鑺墖娴嬭瘯