python - 在 PyUnit 中运行任何测试之前,在开始时只运行一次方法

标签 python unit-testing tdd python-unittest

我使用 PyUnit 为我的代码编写单元测试。每次运行任何测试之前都会调用设置方法。 有没有一种方法可以定义一个方法,该方法将在开始时在运行任何测试之前只运行一次?

请帮忙 谢谢你

最佳答案

您可以使用 setUpClass or setUpModule在 Python 2.7 和 3.2 中。

关于python - 在 PyUnit 中运行任何测试之前,在开始时只运行一次方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8240444/

相关文章:

ruby-on-rails - 如何模拟对 open-uri 的调用

java - 如何在 Android 上使用 Flurry 运行 Robolectric

python - 在 python 中用 cv2 填充图像的 "holes"不起作用

python - 二进制文件转python整数列表

c++ - 用于检查 C++ 方法的 `noexcept` 属性的单元测试

使用 Jasmine 的 TypeScript 中的 AngularJS 单元测试未运行

javascript - 使用异步 ajax 调用的 Sinon/Mocha 测试没有返回 promise

c - 单元测试 : cohabitation of the production-code and the mocked implementation

python - 递归函数 - 计算元组中偶数的个数

python - 如何修复 : 'TypeError: expected string or bytes-like object' when doing unit test on a views. py 函数