title: How can I change the group of a file when executing in a Travis CI build?
body: <p>I've got a Python Travis CI build and a Python unit test executes attempts to change the group of a file on the filesystem. The file was previously created by the unit test, so the user executing the test owns the file.</p>
  
  <p>I'm able to start a sub-shell in which I <em>can</em> run chgrp commands (per <a href="https://docs.travis-ci.com/user/ci-environment/#Group-membership" rel="nofollow">the Travis guidelines</a>), but unfortunately, this screws up the virtualenv set up for my specific Python version (and who knows what else).</p>
  
  <p><strong>How to replicate</strong> (in Travis CI script):</p>
  
  <pre><code>language: python
  sudo: true
  
  python:
      - "3.4"
      - "3.5"
  
  before_install:
      - sudo apt-get -qq update
      - sudo gpasswd -a $USER fuse
  
  script:
      - touch testfile
      - chgrp fuse testfile | echo 0 # this does not work - bad
      - sudo -E su $USER -c "chgrp fuse testfile" # the sudo / su wrapper is required per Travis instructions, see link above - good
      - python --version # reports 3.4 or 3.5 - good
      - sudo -E su $USER -c "python --version" # always reports 2.7 - bad
      - sudo -E su $USER -c "python --version" # always reports 3.2 - bad
  </code></pre>
  
  <p>As I've commented in the block above, running a command which attempts to change the group of the <code>testfile</code> (which is what my unit test code is doing) only works when wrapped with <code>sudo -E su $USER -c</code>.</p>
  
  <p>Unfortunately, when I do this, I lose the ability to access python 3.4 and 3.5 in those script phases (which I've specified above) in the virtualenv that Travis has set up for me.</p>
  
  <p>Any idea how I can achieve both of my goals? (allowing chgrp from the <code>travis</code> non-root user while simultaneously not mucking with the virtualenv or the <code>python</code> on the path?</p>