安装
用pip install -U pytest 命令进行安装 -U 的意思是 如果现在有安装就升级最新版本,如果没有安装就安装最新版本
pycharm中配置pytest
pytest默认使用xxx.py的模式去运行脚本的,想默认以pytest模式运行,得在pycharm中做如下配置
测试是否配置完成
# -*- coding:utf-8 -*-
#auth:duoduo
import pytest
def setup_function():
print("开始执行")
def teardown_function():
print("结束执行")
def test_1():
assert 1 == 1
def test_2():
assert 2==2
def test_3():
assert 2==2
运行结果: