I'm interested in performing potentially unreliable tests using pytest in the form of a sandbox, such as dockers, similar to what continuous integration services do.
I understand that in order to work correctly with the sandbox of the python process, you need isolation at the OS level, for example, running tests in a one-time chroot / container, but in my use case I do not need to protect against intentionally malicious code, only against dangerous mating behavior "random" functions with arguments. A less rigorous sandbox may still be acceptable. But I did not find any plugin that allows you to use any sandbox.
What is the best way to run sandbox tests in pytest?
Update : this question is not about the python sandbox at all , since the test code is run by pytest, and I cannot change the way it is executed, use exec
either ast
or whatever. Also, using pypy-sandbox is not an option, unfortunately, since it is “only a prototype” according to the PyPy functions page .
Update 2 : Hoger Krekel on the pytest-dev mailing list suggests using dedicated testuser via pytest-xdist for user level isolation:
py.test --tx ssh=OTHERUSER@localhost --dist=each
which made me realize that for my CI-like use case:
"" , , , , testuser (/home/testuser,/tmp,/var/tmp, ..).
, testuser + xdist , .
pytest-nodev.