前言:mac 安装pytest 环境:
在
Mac上安装pytest环境,你可以通过多种方式完成,
但最常用的方法是通过pip(Python的包管理工具)。
一、安装 pytest 测试环境:
以下是详细的步骤:
1. 安装或更新pip(如果新的可忽略)
首先,确保你的pip是最新的。打开终端(Terminal),然后输入以下命令来更新pip:
python3 -m pip install --upgrade pip
2. 安装pytest【必要】
安装pytest非常简单,只需在终端中运行以下命令:
pip3 install pytest
或:
pip install pytest
3. 验证安装
安装完成后,你可以通过运行以下命令来验证pytest是否正确安装:
pytest --version
这应该会显示当前安装的pytest版本,如果没有错误信息,那么就表示pytest已经成功安装。
二、 运行无报错,但不执行测试脚本无法在模拟器自动测试apk:
安装完发现运行测试脚本还是不会在模拟器自动测试 apk,发现你的测试脚本里的
类class TestApiDemo:和测试方法def test_api_demo(self):前面没有绿色的运行按钮,说明 pytest 测试环境还没配置好,可以用如下方式解决:
解决步骤:
打开PyCharm 的设置页面:
【mac】
command+,,打开Preference;
【win】
Setting安装 pytest 运行环境:
找到Preference页面的Toos-Python Integrated Tools,点开这个选项卡,看右边,第三个是Testing,看它的下面是不是写着Default test runner,它的后面默认选的是AutoDetect,点击下列表,选pytest,看到ok 按钮上方出现一行警告⚠️,写着pytest runner found in the selected interpreter!,说明没有配置好pytest运行环境,点击ok 按钮可自动安装 python 运行环境。运行测试:
安装完毕,看到测试框架脚本.py文件的类class TestApiDemo:和测试方法def test_api_demo(self):前面均出现绿色运行按钮,基本没问题了,可以点击绿色按钮或右键的绿色运行按钮等运行按钮该测试脚本即可。
启动 pytest 运行按钮.png
注意事项:
测试方法要以 test_开头,比如:def test_api_demo(self)











网友评论