pytest tmpdir是否仅与函数参数关联?

2024-05-20 04:08:14 发布

您现在位置:Python中文网/ 问答频道 /正文

有没有一种方法可以使用pytestfixture tmrdir编写类的测试方法?在文档中,它指定它可以与函数一起使用。 https://docs.pytest.org/en/latest/tmpdir.html

如果有一种方法可以为类中的测试方法传递tmpdir参数,请分享一个例子好吗?你知道吗

我尝试了以下操作,但出现了如下错误: ““

test_method() takes exactly 2 arguments (1 given)"

我的代码:

import pytest

class class_test(TestCase):

    def test_method(self,tmpdir):
        # code

请帮忙。你知道吗


Tags: 方法函数文档httpsorgtestdocspytest