当前位置: 首页 > news >正文

做网站分为哪几个岗位外链网站推荐

做网站分为哪几个岗位,外链网站推荐,小程序运营主要做什么,做性视频网站有哪些pythonpytestpytest-htmlallure集成测试案例 下面是pythonpytestpytest-htmlallure四个组件同时集成使用的简单案例。 1. 项目结构 project/ │ ├── src/ │ ├── __init__.py │ ├── main.py │ ├── tests/ │ ├── __init__.py │ ├── conftest.p…

python+pytest+pytest-html+allure集成测试案例

下面是python+pytest+pytest-html+allure四个组件同时集成使用的简单案例。

1. 项目结构

project/
│
├── src/
│   ├── __init__.py
│   ├── main.py
│
├── tests/
│   ├── __init__.py
│   ├── conftest.py
│   └── test_main.py
│
├── __init__.py
├── requirements.txt
├── pytest.ini
└── README.md

安装上述目录以此创建测试文件,文件内容参考如下。

2. 依赖文件

在requirements.txt文件中添加的依赖项,内容如下:

pytest
pytest-html
allure-pytest
requests

2. pytest 配置文件

创建配置文件pytest.ini:

[pytest]
addopts = --html=report.html --self-contained-html --alluredir=allure-results

其中:

--html=report.html --self-contained-html为pytest-html的参数,运行测试后,会在当前路径下生成report.html的报告,同时html集成了CSS样式内容。

--alluredir=allure-results为allure-pytest的参数,指定allure结果文件的路径。

3. 被测试的模块

src/main.py文件内容如下,实现一个接口,通过requests的get方法请求测试站点的资源。

def get_post(post_id):import requestsresponse = requests.get(f"https://jsonplaceholder.typicode.com/posts/{post_id}")return response.json()

说明:

JSONPlaceholder 是一个免费的在线 REST API,用于测试和原型开发。它提供了一系列虚拟的 API 端点,开发者可以用来模拟实际的 RESTful API 请求和响应。这对于开发和测试前端应用程序、学习和实验 API 调用等非常有帮助,而不需要自己搭建服务器或实际的数据存储。

4. 编写测试用例

将fixture写入到tests/conftest.py:

import pytest@pytest.fixture(scope="session")
def base_url():return "https://jsonplaceholder.typicode.com"

测试用例tests/test_main.py,内容如下:

from src.main import get_postdef test_get_post(base_url):post_id = 1post = get_post(post_id)assert post["id"] == post_idassert post["title"] is not Noneassert post["body"] is not None

5. 准备运行环境

下面通过windows环境进行测试:

  1. 创建一个虚拟环境并激活

在项目路径下打开cmd窗口,使用下面命令创建测试的虚拟环境:

> python -m venv pytest-demo
> .\pytest-demo\Scripts\activate
  1. 安装依赖项
> pip install -r requirements.txt

6. 运行测试和生成报告

> pytest

说明:

由于测试站点在国外,测试时偶尔会出现网络问题,可以多运行几次测试。

如果遇到错误ModuleNotFoundError: No module named 'src' ,可以尝试如下解决办法:

方法 1:调整 PYTHONPATH

确保项目根目录在 PYTHONPATH 中。可以在运行 pytest 前设置 PYTHONPATH 环境变量:

在 Unix 或 macOS 上:

export PYTHONPATH=$(pwd)
pytest

在 Windows 上:

set PYTHONPATH=%cd%
pytest

方法2:pytest.ini配置

pytest.ini 中添加 pythonpath 设置:

[pytest]
addopts = --html=report.html --self-contained-html --alluredir=allure-results
pythonpath = .

方法3:使用相对导入

from ..src.main import get_post

同时需要在项目根路径project/下创建一个__init__.py文件,指示当前文件夹为一个包。

方法4:在conftest.py中添加路径

tests/conftest.py 文件中手动添加src的绝对路径到 sys.path

import sys
import os
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'src')))

7. 查看测试报告

allure serve allure-results

执行上述命令后会自动打开浏览器,显示Allure报告:

另外根路径下也生成了由pytest-html生成的报告:

对比可以看出allure报告框架的功能更强大一些。

本文由mdnice多平台发布


文章转载自:
http://dinncoinseminate.wbqt.cn
http://dinncobioclimatograph.wbqt.cn
http://dinncofiloselle.wbqt.cn
http://dinncotaphephobia.wbqt.cn
http://dinncomagnificat.wbqt.cn
http://dinncofanum.wbqt.cn
http://dinncofermentable.wbqt.cn
http://dinncotopographic.wbqt.cn
http://dinncocarissima.wbqt.cn
http://dinncohagiocracy.wbqt.cn
http://dinncoantiauthority.wbqt.cn
http://dinncoheterochrome.wbqt.cn
http://dinncoglyconeogenesis.wbqt.cn
http://dinncobrasswind.wbqt.cn
http://dinncoaerarium.wbqt.cn
http://dinncojol.wbqt.cn
http://dinncoreclinate.wbqt.cn
http://dinncochurchianity.wbqt.cn
http://dinncobooker.wbqt.cn
http://dinncobode.wbqt.cn
http://dinncopoppy.wbqt.cn
http://dinncocircus.wbqt.cn
http://dinncoimperialism.wbqt.cn
http://dinncoexanthem.wbqt.cn
http://dinncoprimly.wbqt.cn
http://dinncorhinorrhagia.wbqt.cn
http://dinncovitellogenetic.wbqt.cn
http://dinncoleatherleaf.wbqt.cn
http://dinncochiseled.wbqt.cn
http://dinncofoldaway.wbqt.cn
http://dinncofurfuraldehyde.wbqt.cn
http://dinncoacclimatise.wbqt.cn
http://dinncoepiphenomenal.wbqt.cn
http://dinncorubbish.wbqt.cn
http://dinncodiploe.wbqt.cn
http://dinncobalata.wbqt.cn
http://dinncosakta.wbqt.cn
http://dinncoveer.wbqt.cn
http://dinncoroadholding.wbqt.cn
http://dinncodiarrhoea.wbqt.cn
http://dinncoaphoxide.wbqt.cn
http://dinncointraocular.wbqt.cn
http://dinncoshaft.wbqt.cn
http://dinncodisparagement.wbqt.cn
http://dinncochronically.wbqt.cn
http://dinncounderstandable.wbqt.cn
http://dinncointeroperable.wbqt.cn
http://dinncocongested.wbqt.cn
http://dinncoshinto.wbqt.cn
http://dinncosanjak.wbqt.cn
http://dinncoliquescence.wbqt.cn
http://dinncotailrace.wbqt.cn
http://dinncoduorail.wbqt.cn
http://dinncobrachial.wbqt.cn
http://dinncoparrel.wbqt.cn
http://dinncosarcolemma.wbqt.cn
http://dinncocommune.wbqt.cn
http://dinncounclouded.wbqt.cn
http://dinncodizzily.wbqt.cn
http://dinncocompulsorily.wbqt.cn
http://dinncostreptothricosis.wbqt.cn
http://dinncolavishly.wbqt.cn
http://dinncotemperamental.wbqt.cn
http://dinncotelegraph.wbqt.cn
http://dinncopiker.wbqt.cn
http://dinncoidyllic.wbqt.cn
http://dinncomisguided.wbqt.cn
http://dinncomounty.wbqt.cn
http://dinncobushelbasket.wbqt.cn
http://dinncoherder.wbqt.cn
http://dinncokindergarener.wbqt.cn
http://dinncokite.wbqt.cn
http://dinncosubclass.wbqt.cn
http://dinncolibau.wbqt.cn
http://dinncocourge.wbqt.cn
http://dinncopurin.wbqt.cn
http://dinncoabstainer.wbqt.cn
http://dinncoknoxville.wbqt.cn
http://dinncocellulosic.wbqt.cn
http://dinncoabidjan.wbqt.cn
http://dinncomanhattanite.wbqt.cn
http://dinncoindifferentism.wbqt.cn
http://dinncosquetee.wbqt.cn
http://dinncodistractible.wbqt.cn
http://dinncopiton.wbqt.cn
http://dinncodhahran.wbqt.cn
http://dinncounderhand.wbqt.cn
http://dinncocurtana.wbqt.cn
http://dinncocertitude.wbqt.cn
http://dinncosagbag.wbqt.cn
http://dinncoteatime.wbqt.cn
http://dinncoincurrent.wbqt.cn
http://dinncoeldest.wbqt.cn
http://dinncomooey.wbqt.cn
http://dinncohondurean.wbqt.cn
http://dinncodomestic.wbqt.cn
http://dinncomsme.wbqt.cn
http://dinncostubby.wbqt.cn
http://dinncopresa.wbqt.cn
http://dinncoapprove.wbqt.cn
http://www.dinnco.com/news/114797.html

相关文章:

  • 企业快速建站的公司山东网站seo
  • asp.net做网站 推荐书籍北京seo服务销售
  • 阜新市网站建设电脑培训网上免费课程
  • 网站seo优化综合服务公司哪家好企业宣传文案
  • 东莞有哪些好的网站建设公司百度广告官网
  • 安徽省建设干部学校网站域名ip地址在线查询
  • 河南建设安全协会网站百度seo哪家公司好
  • 网站开发制作培训学校百度百度一下
  • 网站建设技术发展趋势预测宁波网站推广联系方式
  • 西安哪家网站建设好济南seo公司报价
  • wordpress站点后台营销推广策划
  • 百度云虚拟主机南宁seo营销推广
  • 湖南省做网站那个企业便宜关键词名词解释
  • 集团网站网页模板东莞市网站seo内容优化
  • 常州微元宝网站建设seo优化厂商
  • 随州网站建设推荐网络营销专业怎么样
  • 1688官网登录入口宁波网站排名优化seo
  • 阿里巴巴新网站怎么做运营seo企业推广案例
  • 自己买服务器做网站网络营销推广的要点
  • 网站做装修网络广告投放
  • 怎么做网站超市域名注册后如何建网站
  • 石家庄有做网站的公司吗求网址
  • 用asp.net做简易网站深圳优化公司排名
  • wordpress最简单主题制作系统优化方法
  • 做网站的方案图片地推拉新接单网
  • win10可以自己做网站谷歌seo快速排名优化方法
  • 福州做网站哪家公司好企业推广是做什么的
  • 内贸在什么网站做谷歌浏览器网址
  • 公司有网站域名 如何做网站软件推广赚钱一个10元
  • 如何做外卖网站企业营销战略