以接口自动化项目为例
打开终端依次输入如下命令:
mkdir PytestDemo
cd PytestDemo
#创建Python项目虚拟环境
python -m venv .env
#激活虚拟环境
source .env/bin/activate
#安装第三方库
pip install requests
pip install pytest
pip install pytest-html
pip install pytest-html-reporter
#将项目依赖保存到requirements.txt文件
pip freeze > requirements.txt
mkdir tests
cd tests
touch test_demo.py
使用Pycharm打开PytestDemo
配置Python Interpreter
在项目根目录新建pytest.ini文件
输入如下内容
[pytest]
addopts = -vs -rf --html-report=./report --title='PYTEST REPORT' --self-contained-html
最终项目目录如下: