反馈测试员python

时间:2016-02-18 17:49:55

标签: python python-2.7

嗨,对于给定的函数,我有2个参数,它们是字符串和Int,但我不知道哪个是第一个。所以我有一个函数“pick_type()”,试图猜测参数的顺序。所以我的问题是当“pick_type()”错误地猜测订单时,如何记录这一点并确保“pick_type()”从不再次尝试该特定订单?

 for iteration in range(0, 10):

    args = []
    print("\n  def test%d(self):" % (iteration))
    for input in range(num_arguments):

        args += pick_type()

    try:
        result = target(*args)
        code = test_to_string(target, args, result)


    except TypeError as error:
        code = test_to_string_exc(target, args, error) 


    for line in code.splitlines():
        print("    "+line)

 def pick_type():
    lista = []

    words = ['rhythms', 'rhythms', 'manager', 'training', 'hotel', 'destroy']
    word = choice(words)
    num = random.randint(-100, 100)

    lists = [word,num]

    choices = choice(lists)


    if choices == word:
        lista.append(word)
    else:
        lista.append(num)


    return lista  

1 个答案:

答案 0 :(得分:0)

我建议将您的方法包装在一个类中,然后您可以拥有一个持久的错误订单列表。我不清楚你的意思是什么意思#34;但不管它是什么,希望这个伪代码能帮助你:

class PickType:
   def __init__(self):
       self._bad_orders = []

   def pick_type(self):
       ...# insert body here
       if order in self._bad_orders:
           ## pick another order
       ## test the new order
       if <order is bad>:
          self._bad_orders.append(order)

   ## if your test for bad orders is performed outside pick_type(), you just need a method to add to the list of bad_orders
   def add_bad_order(self, order):
       self._bad_orders.append(order)