【问题标题】:is it possible to use python setUp and tearDown to adress this是否可以使用 python setUp 和 tearDown 来解决这个问题
【发布时间】:2018-11-18 01:49:03
【问题描述】:

我想设计一些测试用例,每个测试用例都会做同样的操作 喜欢

testA 做:

insomd 模块X
测试
rmmod 模块X

testB

insomd 模块Y
测试
rmmod 模块Y

是否可以将 insmod 和 rmmod 操作放入 setup 和 teardown 中?通过参数或类似的东西。我想在这里使用 setup/teardown 进行准备和清理操作,但不在测试功能中。

【问题讨论】:

标签: python python-unittest


【解决方案1】:

当然,只需 import os 并在 testA 的设置和拆卸中运行 os.system('insmod moduleX')os.system('rmmod moduleX'),对于 testB,进行必要的修改

看看here如何在python中调用外部命令。

您将要更改操作系统,因此如果在拆卸发生之前有什么东西中断了您的测试,您可能会使系统处于不一致的状态。

【讨论】:

  • 不,我不是问是否可以将 shell 命令放入 python 脚本中,我是问如何使用 setup 和 teardown 为不同的测试用例做不同的事情
  • 您需要将它们移动到不同的测试套件。
猜你喜欢
  • 2020-01-31
  • 2011-07-16
  • 1970-01-01
  • 2021-01-16
  • 2015-08-10
  • 2020-01-14
  • 1970-01-01
  • 1970-01-01
  • 2019-04-07
相关资源
最近更新 更多