title: How do I import a py module which reads data from a json file?
body: <p>I am new to pytest testing and trying to test a python module main.py which includes classes and functions, and which also reads a static config.json file. When I import the main module for my pytest and run my test, I get an error that the json file cannot be found. I am looking to run a simple test again the classes I defined in main.py and do not need the config.json data.</p>
  
  <p>I've tried placing my pytest in different parts of the project directory, but it does not help. I have also tried creating a package from my program, including a reference to the config.json file in a MANIFEST.in file, and my config.json file was installed with my package, but I still got the same problem where the config file could not be found.  </p>
  
  <p>My directory</p>
  
  <pre><code>Project
     src 
        code
           main.py
           config.json
           tests
              test_main.py
  </code></pre>
  
  <p>my pytest test_main.py:</p>
  
  <pre><code>import sys, os
  myPath = os.path.dirname(os.path.abspath(__file__))
  sys.path.insert(0, myPath + '/../')
  
  import pytest
  from main import Reservation
  
  @pytest.mark.runme
  def test_reservation():
      starttime = "2019-05-03 12:30"
      booktime = "2019-05-02 8:00"
      newreservation = Reservation("002", "manicure", "normal", starttime, booktime, 1, 30)
      assert newreservation.get_serv_name() == "manicure"
  </code></pre>
  
  <p>from main.py at line 436:</p>
  
  <pre><code>with open('config.json', 'rt') as fin:
      config = json.load(fin)
      business_name = config['business_name']
  </code></pre>
  
  <p>I expect to be able to import the Reservation class from main.py and run a test against it, but I get an error the config.json file cannot be found:</p>
  
  <p>pytest error:</p>
  
  <pre><code>==================================== ERRORS ====================================
  ___________ ERROR collecting src/MiYE/tests/test_u01_load_clients.py ___________
  test_main.py:6: in &lt;module&gt;
      from main import Reservation
  ../main.py:436: in &lt;module&gt;
      with open('config.json', 'rt') as fin:
  E   FileNotFoundError: [Errno 2] No such file or directory: 'config.json'
  =============================== warnings summary ===============================
  </code></pre>
  
  <p>btw, I can access the file config.json successfully when I run main.py as a regular python file (not an imported module). Also, the problem persists when the test is moved from /test to the code directory.</p>