- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试将三个不同的固定装置传递给我的 pytest.mark.parameterize
装饰器,如下所示:
@pytest.mark.parametrize("credentials, return_code", [
(user1, 200),
#(user2, 200),
#(user3, 401)
])
def test_login():
assert True
# Actual test uses response.return_code == return_code
但是,我收到一条错误消息:
NameError: name 'user1' is not defined
虽然这是不正确的,我已经在 conftest.py
中定义了它:
user1_info = [('user1', 'password')]
@pytest.fixture(params=user1_info)
def user1(request):
return request.param
如果我把我的测试改成这样, fixture 就可以工作了:
def test_login(user1):
assert True
# Actual test uses response.return_code == return_code
问题是,如果我这样做,我必须编写三个单独的测试,一个用于每个 fixture ,一个用于每个 status_code 检查。如果我可以使用 parameterize
,我可以使用一个函数并检查用户/预期的返回代码。
我如何利用我的固定装置作为 pytest.mark.parameterize
装饰器的一部分?
最佳答案
要将灯具作为参数化参数传递,请将它们作为字符串引用并使用关键字参数 indirect=['arg_name', ...]
。
然后使用参数名称 credentials
和 return_code
作为测试函数的参数。
@pytest.mark.parametrize(
"credentials, return_code",
[
("user1", 200),
("user2", 200),
("user3", 401),
],
# Only the `credentials` parameter is a reference to the
# fixture. The `return_code` should be passed as is.
indirect=["credentials"],
)
def test_login(credentials, return_code):
return True
pytest 的 parametrize
魔法与 indirect
的文档可以在这里找到: https://docs.pytest.org/en/stable/example/parametrize.html#apply-indirect-on-particular-arguments
关于python - 如何将固定装置传递给 pytest.mark.parametrize?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47726000/
我需要一个可以显示每个主题的最高分数计数的查询。假设 3 名学生的科学成绩需要达到 98 分 count marks subject 3 98 Maths 最佳答案 首先找到每个
对于Java中的Concurrent-Mark-Sweep垃圾收集器;我不清楚这两个阶段有什么不同。为什么需要并发标记?初始标记没有找到所有 Activity 对象吗? 最佳答案 使用CMS,即所谓的
我想知道组查询的工作 假设有一张表Student(id,name,marks) 现在如果我想输出除得分最高的学生之外的所有学生,为什么这个查询不起作用? SELECT * FROM Students
我在 VSCode 中使用 markdown 预览器,希望能够突出显示“.md”文件中的某些文本并将其包装在“”标签中,以便在查看 markdown 文件时突出显示以其呈现的格式。 有没有快速简便的方
Pragma 标记在 Localizable.strings 文件中不起作用。如果我在 Localizable.strings 中添加第二个 MARK: (#pragma mark),xcode 会出
我喜欢使用 vim(在 ms windows 上),我想每个人都有一个最喜欢的编辑器,这是我的。 在一台特定的 PC 上,我遇到了与 mark[a-zA-Z] 命令有关的问题。它不适用于字母 a 和
import java.util.*; public class loops { public static void main (String []args) { Scann
我喜欢使用 vim(在 ms windows 上),我想每个人都有一个最喜欢的编辑器,这是我的。 在一台特定的 PC 上,我遇到了与 mark[a-zA-Z] 命令有关的问题。它不适用于字母 a 和
假设我有一个包含函数的列表:。如果我想使用BASCH对它们进行基准测试,我可以这样做:。它运行得很好。然而,我对这种方法有两个小毛病。。看来,Exprs对Mark的论证应该会有所帮助,因为它允许我做一
我正在编写我的 k8s 升级 ansible 剧本,其中我需要做 apt-mark unhold kubeadm .现在,我试图避免使用 ansible command或 shell调用模块apt如果
我的 View 区域中有 2 个并排的列表控件。当我在 list1 中选择一个项目时,会填充 list2。当在 list2 中选择一个项目时,详细信息会显示在它之外的另一个 View 中。 因此,当在
目标是用括号标记字符串中的每个匹配项,并为每个匹配项标记返回相同的字符串 即: Pattern = "\\d+" Text = "e3e3e" wanted result = "e(3)e(3)e"
在我通过启动并运行一个 100% 覆盖率的小型 C++ 测试项目来了解更多关于自动化测试的过程中,我遇到了以下问题——尽管我所有的实际代码行和所有执行分支都是被测试覆盖,lcov 仍然报告两行未经测试
我实现了一个小函数,它解析 SQL INSERT 语句并在光标位于列名上时突出显示列值,反之亦然。 然后我想添加一种在列名和列值之间快速跳转的可能性。我在我的实现中使用了 push-mark,所以我可
我有一个变量searchString与包含字符串。我必须列出 titles我想要的过滤器 searchString 。我尝试使用标签 用于突出显示一段标题,但目前还无法做到。 我尝试实现一个具有 2
我在使用 AppCode IdeaVim 插件时遇到了这个奇怪的问题。安装后一切似乎都正常工作。然而我遇到了一些非常烦人的事情。每当我尝试通过运行 :marks 命令或 :registers 列出标记
这是一个关于正确实现Java的InputStream接口(interface)的问题。 我的实现不支持标记/重置功能。因此,它从 markSupported 方法返回 false。在这种情况下我应该如
我正在构建我的第一个 Tailwindcss基于网站。我想修改 标签使标记的文本看起来更漂亮。 这是我做的: mark { @apply inline-block pr-1 pl-1 py-0
我看到默认的 背景颜色为黄色。在哪里定义的? 我没有在 reference 中找到它,CSS2 system colors中没有对应的颜色. 颜色总是一样的吗?它取决于浏览器或 GUI 设置吗?有什么
我无法想出正确的正则表达式字符串来删除多个 ?人物。我想按顺序更换多个?用一个 ?,但是要转义哪些字符...正在转义我。 示例输入: Is this thing on??? or what??? 期望
我是一名优秀的程序员,十分优秀!