dimanche 22 décembre 2019

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

Using command py.test ./Combinatory_testing.py -v on terminal to be able to run it in py.test When I run it ,it is giving me test failed because of the function "is_valid_combination" but the problem is that I want the assertion to be always pass and to just skip is_valid_combination cases, not to add it to the test.

Do you have any idea what I am doing wrong?

#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)

Aucun commentaire:

Enregistrer un commentaire