繁体   English   中英

我试图在断言错误 python 中跳过某些情况

[英]I am trying to pass skip some cases in assertion error python

在终端上使用命令py.test ./Combinatory_testing.py -v能够在 py.test 中运行它当我运行它时,由于函数“is_valid_combination”,它让我测试失败,但问题是我想要断言总是通过并跳过 is_valid_combination 情况,而不是将其添加到测试中。

你知道我做错了什么吗?

#importing libraries
from allpairspy import AllPairs
import pytest


#parameters are mainly:
#Computer names
# OS
# Network to be connected to these PC's
# Contract type for the employers

parameters = [
    ["HP", "DELL"],
    ["98", "NT", "2000", "XP"],
    ["Internal", "Modem"],
    ["Salaried", "Hourly", "Part-Time", "Contr."],
]

#Uncomment below to print all the possible Combinations with less numbers for sure using the function AllPairs

# print("PAIRS:")
# for i, pairs in enumerate(AllPairs(parameters)):
#    print(i,pairs)
#


def is_valid_combination(brand, operating_system, network, contract):
    """
    This is a filtering function. Filtering functions should return True
    if combination is valid and False otherwise.
    """

    # Brand DELL does not support Windows 98
    if "98" == operating_system and "DELL" == brand:
        return False

    # HP does not work with XP
    if "XP" == operating_system and "HP" == brand:
        return False

    # Contractors can't work on "Internal" network.
    if "Contr." == contract and network == "Internal":
        return False

    return True


#Uncomment below to print all the possible Combinations with less numbers for sure using the function AllPairs After Filtering the
#impossible combinations

#
#print("PAIRWISE:")
# for i, pairs in enumerate(AllPairs(parameters, filter_func=is_valid_combination)):
#     print("{:2d}: {}".format(i, pairs))

def function_to_be_tested(brand, operating_system, Network, Contract):
    return True

class TestParameterized(object):
    @pytest.mark.parametrize(["brand", "operating_system", "network", "contract"], [
        value_list for value_list in AllPairs([
            ["HP", "DELL"],
            ["98", "NT", "2000", "XP"],
            ["Internal", "Modem"],
            ["Salaried", "Hourly", "Part-Time", "Contr."],
        ])
    ])

    def test_assert(self,brand,operating_system,network,contract):
        assert is_valid_combination(brand,operating_system,network,contract)

你忘了提到代码示例是从库allpairspy获取和改编的: https : //github.com/thombashi/allpairspy 该库从作为输入给出的列表中生成某些组合。 但是,您已从对filter_func=is_valid_combination的调用中删除了命名参数filter_func=is_valid_combination AllPairs 如果我正确理解您的问题,再次添加此内容将确保仅生成此类组合,您的断言将通过。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM