title: pytest get the file path of current test file
body: <p>I can't seem to get the file path of the current file being tested in pytest.</p>
  
  <p>For instance consider something like the following directory structure:</p>
  
  <pre><code>devops_scripts
  ├── devops_utilities
  │   ├── backupMonthly.py
  │   ├── generateAnsibleINI.py
  │   └── tests
  │       └── test_backup.txt
  ├── monitoring
  │   ├── analyizeCatalinaLog.py
  │   ├── fetchCatalinaLogs.py
  │   └── getaccountcredit.py
  ├── pi_provisioning
  │   ├── piImageMake.sh
  │   ├── piImageRead.sh
  │   └── piImageSquashSd.py
  └── script_utilities
      ├── README.md
      ├── __init__.py
      ├── execute.py
      ├── path_handling.py
      ├── sql_handling.py
      └── tests
          ├── sourcedirfortests
          │   ├── file1.txt
          │   └── file2.txt
          ├── test_ansible.txt
          └── test_execute.txt
  </code></pre>
  
  <p>If I run <code>pytest</code> from the top level it will descend to testing <code>test_execute.txt</code>. When <code>test_execute.txt</code> is under testing how do I get the file path to it? (I can get the <code>rootdir</code> through <code>os.path.abspath('.')</code> but that is not what I need)</p>
  
  <p>(I need to be able to set these paths in order to test some execution things on <code>file1.txt</code> and <code>file2.txt</code>. I also need this to work no matter how deeply nested the various things I am trying to test.) I am not so interested in setting up specific temp testing directories and taking them down, etc. I just need the path of the file which is being tested.</p>
  
  <p>I have tried things like:</p>
  
  <pre><code>&gt;&gt;&gt; print os.path.abspath(__file__)
  </code></pre>
  
  <p>But that just yields: <code>UNEXPECTED EXCEPTION: NameError("name '__file__' is not defined",)</code></p>
  
  <p>I am not above even accessing some internal functions / objects in py.test</p>
  
  <p>(I should add that I need this to work in Python 2.7 and Python 3.x)</p>