[TIP] mocking a file in /proc

James Cooke me at jamescooke.info
Tue Jan 24 06:15:12 PST 2017


My suggestion is that you checkout pyfakefs:
https://github.com/jmcgeheeiv/pyfakefs |

Although I've not used it for a year or so, I've had previous good
experience using it for mocking out entire file systems, and I think you
should be able to create the files you want under `/proc` for your test
suite with no problem.



On Tue, 24 Jan 2017, at 02:08 PM, Johan Olsen wrote:

> Hello,

> I would solve this by running my program in a chroot environment in
> some way. Chroot is used to change the apparent root directory for
> some running process and its children. You can then set up a mock
> /proc under e.g. /tmp/mock, and run your tests with chroot under
> pretense that /tmp/mock is your actual root folder. From python you
> can do this with os.chroot.
> Regards,

> Johan Olsén



> 2017-01-24 14:51 GMT+01:00 David Palao <dpalao.python at gmail.com>:

>> Hello,

>>  I am writing a program that does something based on information read
>>  from /proc (the target OS is linux). But I have some problems
>>  figuring
>>  out how to mock the /proc filesystem, or at least, some files in it.

>>  The rationale is that I want to change some files inside /proc to

>>  simulate different configurations of the host computer so that I can
>>  run my functional tests against those different configurations.


>>  I was thinking in using docker for this task. But

>>  1) this is offtopic here :)

>>  and

>>  2) I would like to learn what is the standard way to deal with such
>>  situations. If there is a "standard way" at all... I mean, what am I
>>  supposed to do from the point of view of TDD?


>>  I would appreciate if someone with experience in such problems could
>>  share some advice.


>>  Best,



>>  David


>>  _______________________________________________

>>  testing-in-python mailing list

>> testing-in-python at lists.idyll.org

>> http://lists.idyll.org/listinfo/testing-in-python

> _________________________________________________

> testing-in-python mailing list

> testing-in-python at lists.idyll.org

> http://lists.idyll.org/listinfo/testing-in-python


James Cooke Backend software developer CV PDF:
http://jamescooke.info/docs/james_cooke_cv.pdf Website:

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/testing-in-python/attachments/20170124/6e488cd6/attachment.htm>

More information about the testing-in-python mailing list