| Name | Date | Size | #Lines | LOC | ||
|---|---|---|---|---|---|---|
| .. | - | - | ||||
| testModule/ | 22-Oct-2025 | - | 5,061 | 4,005 | ||
| conftest.py | D | 22-Oct-2025 | 1.2 KiB | 34 | 14 | |
| hdc_recv_all_test.py | D | 22-Oct-2025 | 9.5 KiB | 295 | 235 | |
| help.log | D | 22-Oct-2025 | 4.6 KiB | 76 | 65 | |
| main.py | D | 22-Oct-2025 | 1.9 KiB | 57 | 30 | |
| prepare.py | D | 22-Oct-2025 | 5.4 KiB | 151 | 108 | |
| pytest.ini | D | 22-Oct-2025 | 786 | 26 | 24 | |
| readme.md | D | 22-Oct-2025 | 3.8 KiB | 154 | 108 | |
| requirements.txt | D | 22-Oct-2025 | 138 | 10 | 10 |
readme.md
1# pytest 测试框架 for hdc auto test 2 3## 参数指导 4 5参数可在pytest.ini中配置,也可以在命令行中配置,优先级:命令行 > pytest.ini 6-s: 显示输出调试信息,包括print打印的信息,但是不会写入到report 7-v: 显示更详细的信息 8-n:支持多线程运行脚本(需要保持用例彼此独立) 9--reruns NUM:失败用例重跑次数 10-x:表示只要有一个用例报错,那么测试停止 11-k:模糊匹配字符串进行用例跑测 12-m: 标记用例Level执行级别 13 14## 目录结构 15 16目录结构如下: 17 18```shell 19~/hdc/test/scripts/ 20├─reports # 测试报告目录 21├─resource # 测试资源文件,存放测试过程中使用到的文件,可使用prepare.py进行资源准备 22├─testModule 23| ├─output # 命令行输出文件,例如:重定向文件,zip文件 24| ├─test_hdc_base.py # hdc基础测试 25| ├─test_hdc_file.py # hdc文件测试 26| └─utils.py # 工具 27├─main.py # 测试用例执行入口 28├─prepare.py # 资源准备脚本 29├─pytest.ini # pytest配置文件 30└─requirements.txt # 依赖文件 31``` 32 33## 测试用例编写 34 35### 1. 新建测试套(py文件) 36 37建议文件名格式为:test_hdc_模块名.py 38 39### 2. 编写测试用例 40 41```python 42import pytest 43from utils import GP, check_version, load_gp # 注意这里load_gp不能缺省 44 45class TestClassExample: 46 test_table = ['A', 'B', 'C'] 47 @classmethod 48 def setup_class(self): 49 print("这里配置测试类执行前的操作") 50 51 52 @classmethod 53 def teardown_class(self): 54 print("这里配置测试类执行后的操作") 55 56 57 @pytest.mark.自定义标签 # 这里配置用例自定义标签,在pytest.ini中可配置自定义标签参数,以运行标记的测试用例 58 @pytest.mark.repeat(2) # 这里配置用例重跑次数 59 @check_version("Ver: 3.1.0a") # 这里配置用例最低可执行的版本,低于该版本的环境将跳过用例 60 @pytest.mark.parametrize("test_item", file_table) # 这里配置参数化,支持列表,元组,字典 61 def test_example(self, test_item): 62 assert test_item in self.test_table # 这里编写测试用例,支持assert断言 63``` 64 65## 测试资源配置 66 67进入scripts目录,配置环境准备,执行以下命令, 68 69```shell 70python prepare.py 71``` 72 73如已配置环境,执行以下命令,安装缺失的依赖: 74 75```shell 76python prepare.py -r 77``` 78 79如已配置环境,执行以下命令,更新资源文件: 80 81```shell 82python prepare.py -s 83``` 84 85如已配置设备,执行以下命令,更新设备信息: 86 87```shell 88python prepare.py -c 89``` 90 91 > **说明:** 92 > 93 >1、新环境执行一次资源环境配置即可; 94 > 95 >2、配置过程存在需要确认的设备信息,请根据提示按下回车确认; 96 > 97 >3、如需生成软链接文件,需使用管理员权限执行资源配置命令; 98 > 99 >4、需要联网获取的资源文件,如存在无法下载的情况,请根据提示手动下载并解压到resource目录。 100 101## 测试执行 102 103配置完成环境后即可执行测试用例,执行用例有以下两种方式 104 105### 方式一 106 107```shell 108python main.py 109``` 110 111执行参数在pytest.main中配置 112 113### 方式二 114 115- 执行所有用例 116 117```shell 118pytest ./ 119``` 120 121- 执行指定目录下所有用例 122 123```shell 124pytest ./testModule/ 125``` 126 127- 执行指定测试文件 128 129```shell 130pytest ./testModule/test_hdc_base.py 131``` 132 133- 执行指定测试用例类 134 135```shell 136pytest testModule/test_hdc_base.py::TestClassExample 137``` 138 139- 执行指定测试用例 140 141```shell 142pytest testModule/test_hdc_base.py::TestClassExample::test_example 143``` 144 145- 执行稳定性用例 146 147```shell 148pytest -m ST 149``` 150 151## 测试报告 152 153执行python main.py后,会在reports目录下生成测试报告 154