gpt4 book ai didi

python - 在继承 softest.TestCase 时, fixture 缺少 1 个必需的位置参数错误

转载 作者:行者123 更新时间:2023-12-04 16:46:08 25 4
gpt4 key购买 nike

当我继承 softest.TestCase 时,我收到错误缺少 1 个必需的 fixture 位置参数
注意:如果我删除 softest.TestCase 测试将执行但在使用时失败。
我的pytest代码如下:
test_compyte.py 的内容

import softest

class Testcompute (softest.TestCase):

def test_compute(self,param1):
print("param is ",param1)
assert param1 > 4

if __name__ == '__main__':
softest.main()
conftest.py 的内容
import pytest
import selenium
from selenium import webdriver

def pytest_addoption(parser):

parser.addoption("--templatename", action="store", help="run all combinations")


def pytest_generate_tests(metafunc):

if "param1" in metafunc.fixturenames:
if metafunc.config.getoption("templatename"):
end = int(metafunc.config.getoption("templatename"))
else:
end = 1
metafunc.parametrize("param1", range(end))
错误日志
self = <parameter.test_compute.Testcompute testMethod=test_compute>
method = <bound method Testcompute.test_compute of <parameter.test_compute.Testcompute testMethod=test_compute>>

def _callTestMethod(self, method):
> method()
E TypeError: test_compute() missing 1 required positional argument: 'param1'

TypeError
================================================================ short test summary info =================================================================
FAILED test_compute.py::Testcompute::test_compute - TypeError: test_compute() missing 1 required positional argument: 'param1'
1 failed in 0.22s

最佳答案

变通解决方案:而不是继承 softest.TestCase , 创建 softest.TestCase 的对象测试里面。
test_compyte.py 的更新内容:

class Testcompute: 
def test_compute(self, param1):
case = softest.TestCase()
print("param is ", param1)
assert param1 > 4

if name == 'main':
softest.main()

关于python - 在继承 softest.TestCase 时, fixture 缺少 1 个必需的位置参数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63978287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com