【问题标题】:How to test the execution order of several functions in python?如何在python中测试几个函数的执行顺序?
【发布时间】:2015-04-28 18:18:19
【问题描述】:

我有几个更新功能。它们必须按严格的顺序执行。

例如

def update1(a1):
  do_something...

def update2(a1, a2):
  do_something...

def update3(a1):
  do_something...


def process(a,b):
  update1(a)
  update2(a,b)
  update3(a)

process 中,所有update 函数都必须按此顺序执行。

如何编写单元测试来测试process内部的执行顺序?


我不是问测试的执行顺序不是喜欢这些问题

Python unittest.TestCase execution order

Execution order on python unittest

【问题讨论】:

    标签: python unit-testing pytest


    【解决方案1】:

    问自己一个问题,“为什么顺序很重要?”如果您无法从外部区分呼叫的差异,则无需对其进行测试。 例如,如果这些是数据库更新,您必须编写一个记录更新顺序的数据库模型,或者编写一个 select 语句,以检查更新是否以正确的顺序发生。

    【讨论】:

      猜你喜欢
      • 2021-06-22
      • 1970-01-01
      • 2020-07-07
      • 2019-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多