繁体   English   中英

使用 pytest 和 pyfakefs 测试 isinstance(PosixPath)

[英]Testing isinstance(PosixPath) using pytest with pyfakefs

在我的代码中,我测试 config_location 是config_location还是NonePosixPath

if isinstance(self.config_location, (PosixPath, type(None))):
    ...

这在使用普通的 python 解释器运行时工作正常,但在我使用 pyfakefs 的 pytest 测试期间失败,因为 pyfakefs 对象的类型为pyfakefs.fake_pathlib.FakePathlibModule.PosixPath 这里明显的解决方案是将 pyfakefs 导入到测试代码中,并将pyfakefs.fake_pathlib.FakePathlibModule.PosixPath添加到 isinstance 元组,但这种方法对我来说似乎很笨拙。

一定有更好的方法 ?

测试PurePath反而有效。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM