Pytest 框架中带有参数化类夹具的单元测试用例抛出错误

问题描述 投票:0回答:1

我是 pytest 框架的新手。我需要在类上创建一个带有参数化夹具的测试用例。我创建了如下测试用例。但它抛出一个错误: TypeError:TestClass.test_case_parameterized() 缺少 1 个必需的位置参数:'文件名' 请有人帮忙解决这个问题

import pytest
import unittest
from moto import mock_aws

@pytest.mark.parametrize("filename", ["testFile1.txt", "testFile2.txt"])
@mock_aws
class TestClass(unittest.TestCase):
    def test_case_parameterized(self, filename):
        print(f"filename = {filename}")

        #further aws api call processing`
pytest
1个回答
0
投票

如果你想使用pytest框架,你可以更改你的代码如下:

import pytest
from moto import mock_aws

@pytest.mark.parametrize("filename", ["testFile1.txt", "testFile2.txt"])
@mock_aws
class TestClass():
    def test_case_parameterized(self, filename):
        print(f"filename = {filename}")
        # further aws api call processing
        # your assertion


© www.soinside.com 2019 - 2024. All rights reserved.