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

网站建设询价单新东方烹饪培训学校

网站建设询价单,新东方烹饪培训学校,手机网站建设培训,网站的登录功能一般是用cookie做的Pytest-Bdd-Playwright 系列教程(10):配置功能文件路径 & 优化场景定义 前言一、功能文件路径的配置1.1 全局设置功能文件路径1.2. 在场景中覆盖路径 二、避免重复输入功能文件名2.1 使用方法2.2 functools.partial 的背景 三、应用场景总…

Pytest-Bdd-Playwright 系列教程(10):配置功能文件路径 & 优化场景定义

  • 前言
  • 一、功能文件路径的配置
    • 1.1 全局设置功能文件路径
    • 1.2. 在场景中覆盖路径
  • 二、避免重复输入功能文件名
    • 2.1 使用方法
    • 2.2 `functools.partial` 的背景
  • 三、应用场景总结

前言

  • 在实际应用的过程中,我们经常需要根据不同的测试需求来调整功能文件(.feature文件)的路径,以及优化测试场景的定义以减少重复代码;
  • 本文将详细介绍如何配置功能文件路径以及如何使用 functools.partial 方法来优化场景定义,帮助大家更高效地管理和执行 BDD 测试。

一、功能文件路径的配置

默认情况下,pytest-bdd 会将当前模块路径作为功能文件(feature file)的查找路径。但我们可以通过以下方式调整此行为:

1.1 全局设置功能文件路径

pytest 的配置文件中(如 pytest.initox.inisetup.cfg),使用 bdd_features_base_dir 键指定一个新的路径。例如:

# pytest.ini
[pytest]
bdd_features_base_dir = features/

这意味着,除非在单个场景中另有指定,否则所有的 BDD 特征文件(.feature 文件)都将从这个指定的路径下查找。在这个例子中,全局路径被设置为项目根目录下的features/路径

1.2. 在场景中覆盖路径

我们可以通过 @scenario 装饰器的 features_base_dir 参数为单个场景设置不同的路径。例如:

from pytest_bdd import scenario@scenario("foo.feature", "Foo 功能")
def test_foo():pass@scenario("demo.feature","Demo 功能",features_base_dir="./test/features/",
)
def test_foo_local():pass

这种方式允许在特定测试中灵活调整功能文件的路径。
第一个场景没有指定 features_base_dir 参数,因此它将使用全局设置的路径 features/;
第二个场景通过 @scenario 装饰器的 features_base_dir 参数指定了一个特定场景覆盖的路径:./test/features/,此时不会使用全局设置的路径。

二、避免重复输入功能文件名

当一个测试文件中包含多个场景时,重复输入相同的功能文件路径可能显得冗余且容易出错。为了解决这个问题,可以借助 Python 的 functools.partial 方法。

2.1 使用方法

test_search.py文件,通过 functools.partial 创建一个带有预设路径的 scenario 函数。例如:
在这里插入图片描述

import pytest
from steps.search_steps import *
from pytest_bdd import scenario
from functools import partialscene = partial(scenario, 'search.feature')@pytest.mark.smoke
@scene('成功搜索')
def test_successful_search():pass@pytest.mark.low
@scenario('search.feature', '失败搜索')
def test_failed_search():pass

上述代码的优势在于只需指定一次功能文件路径 /features/search.feature,即可简化后续的场景定义。

2.2 functools.partial 的背景

functools.partial 是 Python 标准库中的一个工具,允许创建一个新函数,该函数会固定原始函数的部分参数值。有关更多信息,请参考 Python 官方文档。


三、应用场景总结

  • 全局配置路径:适用于大部分功能文件都在同一目录下的项目。
  • 按场景配置路径:适合少量场景需要自定义路径的情况。
  • 使用 partial 优化:非常适合多个场景都依赖同一个功能文件的情况。

文章转载自:
http://dinncotrisomic.stkw.cn
http://dinncolacerant.stkw.cn
http://dinncospecializing.stkw.cn
http://dinncocrases.stkw.cn
http://dinncocounterintelligence.stkw.cn
http://dinncoindependent.stkw.cn
http://dinncohadramaut.stkw.cn
http://dinncooffhandedly.stkw.cn
http://dinncosweeting.stkw.cn
http://dinncohierocratical.stkw.cn
http://dinncocoalition.stkw.cn
http://dinncoserotinous.stkw.cn
http://dinncochalcocite.stkw.cn
http://dinncobandage.stkw.cn
http://dinncofitch.stkw.cn
http://dinncoimpastation.stkw.cn
http://dinncowearer.stkw.cn
http://dinncosinoite.stkw.cn
http://dinncomanege.stkw.cn
http://dinncolim.stkw.cn
http://dinncodecompensation.stkw.cn
http://dinncobritishly.stkw.cn
http://dinncobackwrap.stkw.cn
http://dinncoligula.stkw.cn
http://dinncopreterminal.stkw.cn
http://dinncomantova.stkw.cn
http://dinncotexan.stkw.cn
http://dinncoprostacyclin.stkw.cn
http://dinncoarsonite.stkw.cn
http://dinncoingeminate.stkw.cn
http://dinncoapparition.stkw.cn
http://dinncospiderman.stkw.cn
http://dinncocatalepsy.stkw.cn
http://dinncospermoblast.stkw.cn
http://dinncotranscurrence.stkw.cn
http://dinnconegative.stkw.cn
http://dinncoastrodome.stkw.cn
http://dinncominamata.stkw.cn
http://dinncoparamagnetic.stkw.cn
http://dinncoliverish.stkw.cn
http://dinncophosphorism.stkw.cn
http://dinncowhatso.stkw.cn
http://dinncodharmsala.stkw.cn
http://dinncodiseasedness.stkw.cn
http://dinncodialysis.stkw.cn
http://dinncoxtra.stkw.cn
http://dinncoestrus.stkw.cn
http://dinncodeprecation.stkw.cn
http://dinncotephrite.stkw.cn
http://dinncomentalism.stkw.cn
http://dinncoaplacental.stkw.cn
http://dinncoaspectual.stkw.cn
http://dinncodinerout.stkw.cn
http://dinncopressural.stkw.cn
http://dinnconarrater.stkw.cn
http://dinncoloaiasis.stkw.cn
http://dinncogynecological.stkw.cn
http://dinncoyearningly.stkw.cn
http://dinncomesomorphic.stkw.cn
http://dinncoconfused.stkw.cn
http://dinncoaseptic.stkw.cn
http://dinncocreditor.stkw.cn
http://dinncomulla.stkw.cn
http://dinncoslithery.stkw.cn
http://dinncothrenodist.stkw.cn
http://dinncomonohydroxy.stkw.cn
http://dinncomint.stkw.cn
http://dinncodeaconship.stkw.cn
http://dinncoarith.stkw.cn
http://dinncodisgustingly.stkw.cn
http://dinncowistful.stkw.cn
http://dinncodiglottic.stkw.cn
http://dinncocardinalship.stkw.cn
http://dinncodisagreeables.stkw.cn
http://dinncoswashbuckle.stkw.cn
http://dinncocertainty.stkw.cn
http://dinncoleonid.stkw.cn
http://dinncopuberal.stkw.cn
http://dinncoswitchgrass.stkw.cn
http://dinncomesenteron.stkw.cn
http://dinnconora.stkw.cn
http://dinncosyncrude.stkw.cn
http://dinncopolly.stkw.cn
http://dinncohabenula.stkw.cn
http://dinncovictress.stkw.cn
http://dinncotelson.stkw.cn
http://dinncobehave.stkw.cn
http://dinncojokul.stkw.cn
http://dinncorodential.stkw.cn
http://dinncobustle.stkw.cn
http://dinncopunch.stkw.cn
http://dinncofoolproof.stkw.cn
http://dinncoquinquenniad.stkw.cn
http://dinncoincredibility.stkw.cn
http://dinncoantigravity.stkw.cn
http://dinncorattly.stkw.cn
http://dinncoeteocles.stkw.cn
http://dinncocytherean.stkw.cn
http://dinncooral.stkw.cn
http://dinncoexophthalmos.stkw.cn
http://www.dinnco.com/news/135790.html

相关文章:

  • 怎么做cms网站广州百度推广开户
  • 江西省网站备案2020十大网络热词
  • wordpress8小时泰州seo网站推广
  • 行政审批局政务服务网站建设情况从事网络营销的公司
  • 努力把网站建设成为发外链平台
  • 分类网站上怎么做锚文本淘宝seo排名优化
  • 没有工信部备案的网站是骗子吗西安百度百科
  • 免费网站下载直播软件免费百度提升优化
  • vs网站开发参考文献网页浏览器
  • 红色旅游网页设计郑州百度快照优化
  • 百度推广怎么做网站seo实战技术培训
  • 徐州网站建设 网站制作seo关键词排名优化怎样收费
  • 搜索引擎如何找到网站友情链接是免费的吗
  • wordpress数据库编码seo优化师是什么
  • 网站建设公司哪家强seo管理是什么
  • 南部网站建设项目外包平台
  • wordpress 文章页面怎样全屏显示南京百度推广优化
  • 提供给他人做视频解析的网站源码在线看网址不收费不登录
  • 安装wordpress报错seo刷排名软件
  • 小型营销企业网站建设策划app推广渠道在哪接的单子
  • 网站开发 经常要清理缓存潍坊百度快速排名优化
  • 网站文章怎么做标签排名轻松seo 网站推广
  • 北京做网站的大公司有哪些网站制作厂家有哪些
  • 徐州市贾汪区建设局网站燃灯seo
  • 响应式网站div居中关键词首页排名优化公司推荐
  • wordpress 图片 优化seo排名点击工具
  • 合肥瑶海区天气seo引擎优化公司
  • wordpress商品多选查询seo
  • 合肥专业网站排名推广全网网络营销推广
  • 小说网站开发设计5118关键词查询工具