相关疑难解决方法(0)

Py.test:从类中参数化测试用例

我目前正在关注这个py.test示例,当我不使用类时,它会工作,但是当我将测试用例引入类时,我失败了.

我设法编写的最小案例如下:

import unittest

import pytest

class FixtureTestCase(unittest.TestCase):

    @pytest.mark.parametrize("test_input,expected", [
    ("3+5", 8),
    ("2+4", 6),
    ("6*9", 42),
    ])
    def test_1(self, a, b):
        self.assertEqual(a, b)
Run Code Online (Sandbox Code Playgroud)

不幸的是,当我执行

  py.test  test_suite.py
Run Code Online (Sandbox Code Playgroud)

我收到错误消息:

  TypeError: test_1() takes exactly 3 arguments (1 given)
Run Code Online (Sandbox Code Playgroud)

如何生成一系列test_1测试?

python automated-tests unit-testing pytest

17
推荐指数
2
解决办法
5251
查看次数

标签 统计

automated-tests ×1

pytest ×1

python ×1

unit-testing ×1