简体   繁体   中英

Testing isinstance(PosixPath) using pytest with pyfakefs

In my code, I test if config_location is an instance of PosixPath or None :

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

This works fine when run with the normal python interpreter, but fails during my pytest tests using pyfakefs, as the pyfakefs object is of type pyfakefs.fake_pathlib.FakePathlibModule.PosixPath . The obvious solution here would be to import pyfakefs into the tested code and add pyfakefs.fake_pathlib.FakePathlibModule.PosixPath to the isinstance tuple, but this approach seems very clunky to me.

There has to be a better way ?

测试PurePath反而有效。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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