title: Accessing resource files in Python unit tests & main code
body: <p>I have a Python project with the following directory structure:</p>
  
  <pre>
  project/
  project/src/
  project/src/somecode.py
  project/src/mypackage/mymodule.py
  project/src/resources/
  project/src/resources/datafile1.txt
  </pre>
  
  <p>In mymodule.py, I have a class (lets call it "MyClass") which needs to load datafile1.txt.  This sort of works when I do:</p>
  
  <p>open ("../resources/datafile1.txt")</p>
  
  <p>Assuming the code that creates the MyClass instance created is run from somecode.py.</p>
  
  <p>The gotcha however is that I have unit tests for mymodule.py which are defined in that file, and if I leave the relative pathname as described above, the unittest code blows up as now the code is being run from project/src/mypackage instead of project/src and the relative filepath doesn't resolve correctly.</p>
  
  <p>Any suggestions for a best practice type approach to resolve this problem?  If I move my testcases into project/src that clutters the main source folder with testcases.</p>