Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.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
unittest引发异常python_Python_Unit Testing_Exception_Pytest - Fatal编程技术网

unittest引发异常python

unittest引发异常python,python,unit-testing,exception,pytest,Python,Unit Testing,Exception,Pytest,我有以下内容来查看数据帧是否为空: def emptyframecheck(data_frame): if data_frame.empty: raise Exception('An empty dataframe was passed.') 我想对其进行单元测试,但运行时: def test_emptyframecheck(): # Given workitem_df = pd.read_csv(os.path.join(HERE, 'test_csv', 'test

我有以下内容来查看数据帧是否为空:

def emptyframecheck(data_frame):
if data_frame.empty:
    raise Exception('An empty dataframe was passed.')
我想对其进行单元测试,但运行时:

def test_emptyframecheck():
    # Given
    workitem_df = pd.read_csv(os.path.join(HERE, 'test_csv', 'test.csv'))

    # When
    emptyframecheck(workitem_df)

    # Then
    assertTrue('An empty dataframe was passed' in emptyframecheck.exception)

我得到一个全局名称
assertTrue
未定义。
工作项df
只是我正在传递的一个空帧。是否有我遗漏的内容或更好的方法?

此错误表示:
assertTrue
未定义。您是否已导入
assertTrue
?如果导入的是测试模块而不是框架,则必须执行以下操作:

testing_module.assertTrue()
如果要直接使用“assertTrue”,应在测试文件的顶部写入以下内容:

from testing_module import assertTrue

可能您指的是pytest.assertTrue或任何用于测试可能重复的外部模块