本文将介绍如何从 DOCX 文档中提取标题为“需求内容”的部分,并将其作为 DeepSeek 模型的输入,生成详细且格式化的测试用例。我们将使用 Python 编写相关脚本,并展示最终的测试用例输出格式。
目标
- 从 DOCX 文件中读取标题为“需求内容”的部分。
- 将提取的内容用作 DeepSeek 模型的输入生成详细的测试用例。
- 将测试用例写入 Excel 文件,包含用例标题、步骤和预期结果等信息。
步骤 1:安装所需库
确保安装以下库:
pip install requests python-docx pandas openpyxl
步骤 2:读取 DOCX 文件并提取需求内容
编写一个函数,从 DOCX 文件中提取标题为“需求内容”的部分:
from docx import Document
def read_requirements_section(file_path, section_title="需求内容"):
doc = Document(file_path)
content = []
capture = False
for para in doc.paragraphs:
if para.style.name == 'Heading 1' and para.text == section_title:
capture = True
continue
if capture:
if para.style.name.startswith('Heading'):
break
content.append(para.text)
return '\n'.join(content)
步骤 3:调用 DeepSeek 模型
定义调用 DeepSeek 模型的函数:
import requests
DEESEEK_API_URL = "http://localhost:11434/api/generate"
def call_deepseek(input_text):
data = {
"input": input_text}
response = requests.post(DEESEEK_API_URL, json=data)
if response.status_code == 200:
return response.json()
else:
raise Exception(f"Error: {
response.status_code} - {
response