- 資訊首頁(yè) > 開(kāi)發(fā)技術(shù) >
- Pytest安裝的詳細教程
本篇內容主要講解“Pytest安裝的詳細教程”,感興趣的朋友不妨來(lái)看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強。下面就讓小編來(lái)帶大家學(xué)習“Pytest安裝的詳細教程”吧!
1、安裝Pytest
命令行執行 pip install pytest
2、快速開(kāi)始
文件路徑
-helloworld
-test_tmp.py
test_tmp.py
"""
文件以test_開(kāi)始 或者 以 _test結尾的py (test不區分大小寫(xiě))
"""
def test_l():
""" test開(kāi)始的函數會(huì )被當做測試用例直接執行"""
assert True
# content of test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
執行 pytest 命令,可以自動(dòng)搜索到test_tmp.py文件中的 2個(gè)test 函數作為測試用例執行。
========================================================= test session starts ==========================================================
platform win32 -- Python 3.7.5, pytest-5.3.5, py-1.8.1, pluggy-0.13.1
rootdir: C:\Users\zengy\Desktop\pytest-demo
collected 2 items
helloworld\test_tmp.py .F [100%]
=============================================================== FAILURES ===============================================================_____________________________________________________________ test_answer ______________________________________________________________
def test_answer():
> assert inc(3) == 5
E assert 4 == 5
E + where 4 = inc(3)
helloworld\tmp.py:17: AssertionError===================================================== 1 failed, 1 passed in 0.04s ======================================================
3、selenium test
from selenium import webdriver
def test_login():
driver = webdriver.Chrome()
driver.get('http://39.107.96.138:3000/signin')
driver.find_element_by_css_selector('#name').send_keys("testuser1")
driver.find_element_by_css_selector('#pass').send_keys('123456') driver.find_element_by_css_selector('input[value="登錄"]').click()
# 添加斷言
# 1.登錄成功應該跳轉到首頁(yè)
current_url = driver.current_url
assert current_url=="http://39.107.96.138:3000/","應該跳轉到首頁(yè)"
# 2. 用戶(hù)名應該為testuser1
username = driver.find_element_by_css_selector('span
[class="user_name"]>a[class="dark"]').text
assert username == "testuser1","登錄用戶(hù)名應該為testuser1"
def test_register():
pass
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng )、來(lái)自互聯(lián)網(wǎng)轉載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權請聯(lián)系QQ:712375056 進(jìn)行舉報,并提供相關(guān)證據,一經(jīng)查實(shí),將立刻刪除涉嫌侵權內容。
Copyright ? 2009-2021 56dr.com. All Rights Reserved. 特網(wǎng)科技 特網(wǎng)云 版權所有 珠海市特網(wǎng)科技有限公司 粵ICP備16109289號
域名注冊服務(wù)機構:阿里云計算有限公司(萬(wàn)網(wǎng)) 域名服務(wù)機構:煙臺帝思普網(wǎng)絡(luò )科技有限公司(DNSPod) CDN服務(wù):阿里云計算有限公司 中國互聯(lián)網(wǎng)舉報中心 增值電信業(yè)務(wù)經(jīng)營(yíng)許可證B2
建議您使用Chrome、Firefox、Edge、IE10及以上版本和360等主流瀏覽器瀏覽本網(wǎng)站