【问题标题】:invoking test case with in another test case in pytest framework在 pytest 框架中的另一个测试用例中调用测试用例
【发布时间】:2017-07-20 09:14:47
【问题描述】:

我正在使用 pytest 进行自动化。

pytest 中是否有任何选项可以在另一个测试用例中调用测试用例。

【问题讨论】:

    标签: python-2.7 pytest pytest-django


    【解决方案1】:

    当然可以。使用 pytest,测试用例是一个简单的函数或方法。

    例如:

    def test_foo():
        assert 2 + 2 == 4
    
    def test_bar():
        assert [1] + [2] == [1, 2]
        test_foo()
    

    考虑一下您为什么要这样做。通常,保持测试解耦会带来好处,例如在测试失败时更容易调试。

    【讨论】:

    • 您的示例不具有代表性,因为测试用例的签名可能包括夹具和其他参数。
    • 我认为这样做的一个原因是编写一个超级测试,其中包含一组特定的子测试,按照需要按顺序排列。即,从例如子目录(或任何地方)“拉入”单个命名测试的单个测试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-25
    • 2016-03-01
    • 2017-08-02
    • 1970-01-01
    • 2020-11-23
    • 1970-01-01
    • 2020-05-21
    相关资源
    最近更新 更多