Has anyone released a Python "mock filesystem" for automated testing?

Peter Hansen peter at engcorp.com
Fri Nov 5 15:26:56 CET 2004


Mike Meyer wrote:
> Peter Hansen <peter at engcorp.com> writes:
> 
>>The term "mock filesystem" refers to code allowing unit
>>or acceptance tests to create, read and write, and manipulate
>>in other ways "virtual" files, without any actual disk
>>access.  Everything is held in memory and therefore fast,
>>without risk of damaging real files, and with none of the
>>messiness of leftover files after testing.
> 
> Just out of curiosity, does your os implement some form of disk in
> memory disk? Go to <URL: http://www.FreeBSD.org/cgi/man.cgi > and
> search for either mfs or md for examples.

I need to be cross-platform, so Windows and Linux must both
be supported.  I suspect there isn't good support on Windows
for the sort of thing you describe.

In any case, though I thank you and Jack for the ideas,
the pure-Python in-memory approach seems to be quite
viable and probably quite a bit simpler.  In addition it
allows testing with paths and operations that could not
be safely supported if real file access was permitted at
all, so I think I'll stick with it.

> Second, consider using os.sep for path seperation, so that testing can
> be done correctly for the OS the project is running on. Or possibly a
> flag to indicate whether or not you want to use os.sep.

I've never had to resort to using os.sep myself.  I use
os.path.split() and os.path.join() and it seems they do the
job for me. ;-)

-Peter



More information about the Python-list mailing list