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

Jack Diederich jack at performancedrivers.com
Fri Nov 5 05:07:30 CET 2004


On Thu, Nov 04, 2004 at 09:31:04PM -0500, Peter Hansen wrote:
> 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.
> 
> Googling the archives and the web suggests that only I and
> Remy Blank have done much along these lines.  I don't see
> any sign that anyone has actually released such a beast
> yet, however.

If linux only support is OK you should check out FUSE
http://fuse.sourceforge.net/
It allows userspace implementations of file systems in python.  The gmailfs
(mount your gmail account) uses it. You could use it to write a 'real' file
system that just has no disk backend store.

It would be easy to implement special files to do things for testing,
  echo '1' > /op/nuke # clean everything
  echo '1' > /op/push # push the state of the filesystem
  echo '1' > /op/pop # restore the state of the filesystem to last 'push'
And any other handy thing you can think of.
It has the advantage that you can use regular python files in your
program.  Bugs in the implementation would hurt testing but that is the
case any way you do it.


Unrelated:
I'm strongly tempted to [re]write a simple webapp like a blog as a
filesystem.  Just put apache on top to handle GETs and cat POSTs/PUTs
directly to the filesystem.  Can't get more unix-y than that!

-Jack



More information about the Python-list mailing list