你們都知道功能測試用例組成的基本要素:用例ID,模塊名,測試用例名稱,前置條件,測試步驟,預期結果,實際結果等等。前置條件以及測試參數化,前面已經講過,如今簡單講一下pytest測試步驟的用法。javascript
若是想在報告中展現測試步驟,須要使用裝飾器@allure.step(),該裝飾器寫在測試步驟函數上面,測試方法直接調用測試步驟函數便可。具體看代碼:html
import allure @allure.step("第一步") def step_1(): step_2() print("打開瀏覽器") @allure.step("第二步") def step_2(): step_3() print("輸入URL") @allure.step("第三步") def step_3(): step_4(username='test',password=123456) print("輸入帳號和密碼") pass @allure.step('第四步:登陸') def step_4(username,password): print("登陸") print(username,password) @allure.step("第五步") def test_login(): step_1()
運行結果:java
輸入命令:pytest -s --alluredir allure_reportweb
================================================================================= test session starts ================================================================================== platform win32 -- Python 3.6.5, pytest-5.4.1, py-1.7.0, pluggy-0.13.1 rootdir: C:\Users\Administrator\Desktop\pytest_test_2019\test_pytest plugins: allure-pytest-2.8.13, celery-4.3.0, cov-2.7.1, forked-1.1.3, html-1.20.0, metadata-1.8.0, rerunfailures-5.0, xdist-1.32.0 collected 1 item test_step.py 登陸 test 123456 輸入帳號和密碼 輸入URL 打開瀏覽器 . ================================================================================== 1 passed in 0.06s ===================================================================================
輸入命令:allure serve allure_report瀏覽器
Report successfully generated to C:\Users\ADMINI~1\AppData\Local\Temp\6826110311791803428\allure-report Starting web server... 2020-06-05 23:41:51.453:INFO::main: Logging initialized @2015ms to org.eclipse.jetty.util.log.StdErrLog Server started at <http://192.168.1.105:49560/>. Press <Ctrl+C> to exit
自動打開瀏覽器,查看報告:session
@allure.step()基本用法就是這樣,建議嵌套使用,單獨使用的意義並不大。eclipse
另外,對測試開發,自動化測試,全棧測試相關技術感興趣的朋友,能夠加入到羣裏學習和探索交流,進羣方式,掃下方二維碼。函數