[英]Testing isinstance(PosixPath) using pytest with pyfakefs
在我的代碼中,我測試 config_location 是config_location
還是None
的PosixPath
:
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.