- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我要考下一个类:
from random import randint
class End(object):
def __init__(self):
self.quips=['You dead', 'You broke everything you can','You turn you head off']
def play(self):
print self.quips[randint(0, len(self.quips)-1)]
exit(1)
我想用 nosetests 测试它,这样我就可以看到该类使用代码 1 正确退出。我尝试了不同的变体,但 nosetest 返回类似的错误
File "C:\Python27\lib\site.py", line 372, in __call__
raise SystemExit(code)
SystemExit: 1
----------------------------------------------------------------------
Ran 1 test in 5.297s
FAILED (errors=1)
当然我可以假设它退出但我希望测试返回 OK 状态而不是错误。对不起,如果我的问题可能很愚蠢。我是 python 的新手,我第一次尝试测试一些东西。
最佳答案
我建议使用 assertRaises context manager .这是确保 play() 方法退出的示例测试:
import unittest
import end
class TestEnd(unittest.TestCase):
def testPlayExits(self):
"""Test that the play method exits."""
ender = end.End()
with self.assertRaises(SystemExit) as exitexception:
ender.play()
# Check for the requested exit code.
self.assertEqual(exitexception.code, 1)
关于testing - 如何测试程序是否退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18176658/
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 3 年前。 Improve
我目前正在从事类似bash的项目。但是,我需要使用数千个测试来测试该项目,而这些测试无法手动检查。这就是为什么我想自动执行测试。 我的程序使用fgets()来获取用户输入。我知道如何直接向程序发送参数
我想在 Android 中编写一个原生应用程序进行测试表面抛物线。是否有任何简单的程序显示如何创建Surfaceflinger 上的表面、寄存器缓冲区和后置缓冲区。 最佳答案 frameworks/b
有一个对象依赖于计时来正常运行。不幸的是,计时持续时间本身太长,无法实时对其进行实际测试,并且由于对象的性质,缩短持续时间违背了测试的目的。 测试此类对象的最佳方法是什么?理想情况下,会有一些可以使用
我首先要说的是,我是一名几乎没有 C++ 经验的大学生。你听对了多少次?我正在使用 libnodave 库中的测试程序 testISO_TCP(简化版)。该程序在连接到 seimens 300 PLC
我正在尝试构建一个非常简单的libodbc++程序。最近,我们注意到了一个奇怪的内存泄漏,我们认为这是由于ODBC++和IDS驱动程序之间的某个地方引起的-我正在编写一个测试来证明这一点。 我使用以下
我对 JavaScript 还很陌生,我有一点疑问。 我创建了这个 JSFiddle:https://jsfiddle.net/AndreaNobili/1up938xf/ 我只定义了执行简单求和(无
我用三个类文件在 IntelliJ 中创建了一个 maven 项目: package mavenKris; import org.apache.hadoop.io.Text; import org.a
我下载了包含 freeglut 的“非官方 OpenGL 软件 SDK”,但我似乎无法让它工作。我在 Windows 上。我在 Visual Studio 2010 或 MinGW g++ 上都没有成
我正在尝试使用 std::async 在 C++ 中调用异步函数按照这个官方cplusplus.com示例代码。 不幸的是,编译失败了。运行时 mingw32-make ,我收到以下错误: main.
我是一名优秀的程序员,十分优秀!