[TIP] mocking a file in /proc
dpalao.python at gmail.com
Tue May 9 02:29:29 PDT 2017
After playing around with systemfixtures, I don't find a way to make
it work for my purposes.
I'm inclined to think that chroot is the answer to my question (thank
you, Johan, for pointing it out from the beginning).
As I explained in my first post, I need a way to provide a fake
filesystem to my functional tests. What I mean by functional tests is
testing from the point of view of the user. What I do for that is: I
call the executable from within my FTs, catch the output and compare
it with the expected output.
To call the executable I use subprocess.Popen. In principle it should
be possible to provide a fake fs to it but, isn't it, at the end of
the day, the same as creating a chroot jail?
Unless there is an easy way to do what I need using systemfixtures (or
fakefs), which I don't see, I think I will need to go to chroot (or
docker). Any recommended tool to create a basic chroot jail with
python in it that I can use to run my program and modify files in
Thanks in advance.
2017-01-24 15:08 GMT+01:00 Johan Olsen <ulf.johan.olsen at gmail.com>:
> 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.
> Johan Olsén
> 2017-01-24 14:51 GMT+01:00 David Palao <dpalao.python at gmail.com>:
>> 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 :)
>> 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.
>> testing-in-python mailing list
>> testing-in-python at lists.idyll.org
More information about the testing-in-python