python - How to replace file-access references for a module under test -
pyfakefs
sounds useful: "was developed modest fake implementation of core python modules support moderately complex file system interactions, , introduced google-wide . . . in september 2006. since then, has received many (well-tested) contributions extend functionality , usefulness, , used in on 900 google python tests."
documentation appears available within docstrings of source code itself. explains module provides following elements:
- fakefile: provides appearance of real file.
- fakedirectory: provides appearance of real dir.
- fakefilesystem: provides appearance of real directory hierarchy.
- fakeosmodule: uses fakefilesystem provide fake os module replacement.
- fakepathmodule: faked os.path module replacement.
- fakefileopen: faked file() , open() function replacements.
documentation not, however, explain how use these elements in testing.
what right way ensure module under test accesses fake filesystem , not real one?
see http://github.com/jmcgeheeiv/pyfakefs code supports both unittest , doctest, plus practical example , tutorial.
Comments
Post a Comment