Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用python unittest拦截c-assert < P>我想用Python中的UNITTest来测试用C++编写的类。如果类的构造函数的参数错误,则该类将引发断言(使用)_C++_Python_Unit Testing_Assertions - Fatal编程技术网

使用python unittest拦截c-assert < P>我想用Python中的UNITTest来测试用C++编写的类。如果类的构造函数的参数错误,则该类将引发断言(使用)

使用python unittest拦截c-assert < P>我想用Python中的UNITTest来测试用C++编写的类。如果类的构造函数的参数错误,则该类将引发断言(使用),c++,python,unit-testing,assertions,C++,Python,Unit Testing,Assertions,我正在尝试: self.assertRaises(SystemExit, ROOT.MyClass, 'invalid_tune') 但它似乎不起作用,我得到: python test.py python: ../Root/MyClass.cxx:53: MyClass::MyClass(std::string): Assertion `false' failed. Aborted 这个班是你的吗?如果是这样,最好引发异常,而不是调用assert,这只会导致中止,对此您几乎无能为力。另外,如

我正在尝试:

self.assertRaises(SystemExit, ROOT.MyClass, 'invalid_tune')
但它似乎不起作用,我得到:

python test.py
python: ../Root/MyClass.cxx:53: MyClass::MyClass(std::string): Assertion `false' failed.
Aborted

这个班是你的吗?如果是这样,最好引发异常,而不是调用
assert
,这只会导致中止,对此您几乎无能为力。另外,如果定义了
NDEBUG
宏,它也不会有任何效果。我期待着这条评论。是的,它是我的,但不是:我不能使用异常。政策,别问我为什么。那是个糟糕的政策!例外是处理C++中构造问题的最有效的方法。我同意,他们更喜欢退出状态,但这是另一个故事。我想找到这个问题的解决方案,然后您可以用
退出
替换断言,这至少允许程序执行一些清理。