文件路径
-helloworld
-test_tmp.py
test_tmp.py
"""
文件以test_开始 或者 以 _test结尾的py (test不区分大小写)
"""
def test_l():
""" test开始的函数会被当做测试用例直接执行"""
assert True
# content of test_sample.py
def inc(x):
return x + 1
def test_answer():
assert inc(3) == 5
执行 pytest 命令,可以自动搜索到test_tmp.py文件中的 2个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(':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.登录成功应该跳转到首页
current_url = driver.current_url
assert current_url==":3000/","应该跳转到首页"
# 2. 用户名应该为testuser1
username = driver.find_element_by_css_selector('span
[class="user_name"]>a[class="dark"]').text
assert username == "testuser1","登录用户名应该为testuser1"
def test_register():
pass
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。