我正在用mockito编写单元测试,并且有一个函数,它有一个特定的行,这会给我带来麻烦:
score_data = json.loads(hdfs_client.read_txt_from_hdfs_with_pipe(score_path).strip())我试过用不同的方式来嘲笑它:
when(mock_hdfs_client).read_txt_from_hdfs_with_pipe(any()).thenReturn(score_cache_entry)和
doReturn(score_cache_entry).when(self.mock_hdfs_client).read_txt_from_hdfs_with_pipe(any())其中'score_cache_entry‘是一个类似json的字符串。
在运行单元测试时,我被抛出了这个属性错误:
score_data = json.loads(hdfs_client.read_txt_from_hdfs_with_pipe(score_path).strip())
AttributeError: 'NoneType' object has no attribute 'strip'发布于 2021-06-08 18:59:09
在您的
when(mock_hdfs_client).read_txt_from_hdfs_with_pipe(any()).thenReturn(score_cache_entry)any()可能是python内置的。如果您使用的是python 3,请尝试使用省略形式:
when(mock_hdfs_client).read_txt_from_hdfs_with_pipe(...).thenReturn(score_cache_entry)https://stackoverflow.com/questions/66746224
复制相似问题