首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >参数化后如何运行拆卸功能/夹具

参数化后如何运行拆卸功能/夹具
EN

Stack Overflow用户
提问于 2019-04-03 10:08:34
回答 1查看 901关注 0票数 3

我试图运行拆卸功能/夹具的整个参数化的一个测试案例。所以我想在我的conftest.py文件中有这样的东西

代码语言:javascript
复制
@pytest.fixture(autouse=True, scope="parametrization")
def parametrization_scope():
    print("First run of parametrization fixture")
    # Executing 100 parametrizations
    yield
    print("Yield run of parametrization fixture")

在我的test.py里,就像

代码语言:javascript
复制
@pytest.mark.parametrize(n-params)
# run initiate fixture here of parametrization
def test():
    # executing n number of times

# run yield fixture here of parametrization
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-04-16 17:17:32

您可以使用一个测试类来解决缺少的“参数化”范围,如下所示:

代码语言:javascript
复制
import pytest

@pytest.fixture(scope="class")
def foo():
    print("setup")
    yield None
    print("teardown")

class TestSum:
    @pytest.mark.parametrize(
        "a,b,c",
        [(3, 5, 8), (2, 4, 6)],
    )
    def test_eval(self, a, b, c, foo):
        assert a + b == c

如果只有TestSum类使用foo,那么甚至可以将foo的定义放在类中。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55492529

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档