pytest是python的一种单元测试框架(非自带,需要安装),与python自带的unitest测试框架相比,使用起来更加简洁、效率更高。总之,一句话,pytest优于unitest。
1.安装pytest (其中-U 指升级原来已经安装的包)并查看安装版本
2.使用pytest的一个demo
# test_open_url.py from selenium import webdriver def test_open_url(): try: driver = webdriver.Chrome() driver.get("http://www.baidu.com") title = driver.title print(driver.title) assert title == '百度一下,你就知道' except AssertionError: raise AssertionError("断言失败!") driver.quit() def testbaidu(): driver = webdriver.Chrome() driver.get("http://www.baidu.com") title = driver.title print(title)
进入命令行模式(Terminal):输入pytest 后回车