Running py.test as another user

We have an extensive test suite that starts an in-memory copy of Postgresql.  I am trying to run these tests from within PyCharm using PyCharm's docker-compose support.  When the test suite gets ready to start Pg it runs initdb which will NOT run as root.  Also the Pg postmaster process will not run as root.

In addition, the in-memory copy of Pg uses /dev/shm, which needs to be resized before the test suite will run completely.  I have a small shell script that I use to start the tests so I don't forget to do this.  It looks like this:

mount -o remount,size=1800m /dev/shm
sudo -E -i -u testuser bash -c "cd /app/tests && PATH=/usr/lib/postgresql/9.6/bin:$PATH pytest -s $@"

How can I accomplish this with PyCharm's py.test integration?

Please sign in to leave a comment.