title: unittest on flask_restful app does not work - stuck on flask server running
body: <p>My tools: Python 3.5.0, flask 1.0.2, mac osx</p>
  
  <p>My problem:
  I have a very simple RESTful app with two endpoints that are working. I wrote two very simple unit tests, via unittest, and they are not proceeding for a reason that I'm not sure of right now. The tests succeed if I do the following:</p>
  
  <ol>
  <li>If I run the server separately, say on <a href="http://127.0.0.1:8015/" rel="nofollow noreferrer">http://127.0.0.1:8015/</a>, (and not setUp() anything)</li>
  <li>And run the tests such that they call requests.get(<a href="http://127.0.0.1:8015/employee/3" rel="nofollow noreferrer">http://127.0.0.1:8015/employee/3</a>)</li>
  <li>the tests run just fine and they pass</li>
  </ol>
  
  <p>The tests just hang if I run the tests with the setUp(self) definition below: </p>
  
  <pre><code>Serving Flask app "testing" (lazy loading)
  Environment: production
  WARNING: Do not use the development server in a production environment.
  Use a production WSGI server instead.
  Debug mode: off
  Running on http://127.0.0.1:8015/ (Press CTRL+C to quit)
  </code></pre>
  
  <p>And here is the pertinent code</p>
  
  <pre><code>def setUp(self):
      self.app = Flask("testing")
      self.app.testing = True 
      self.client = self.app.test_client()
      self.EmployeeId = 4
  
      with self.app.app_context():
          db_connect = create_engine('sqlite:///some.db')       
          self.api = Api(self.app)  
          self.api.add_resource(server.Car, '/car/&lt;employee_id&gt;') # Route_4
          app.run(port=8015, debug=False)
  
  def test_api_can_get_employee_by_id(self):
      res = requests.get(url = 'http://127.0.0.1:8015/car/{}'.format(self.EmployeeId))
      data = res.json()
      self.assertEqual(res.status_code, 200)
      self.assertIn('mazda', data["data"][0]['make_model'])
  </code></pre>
  
  <p>I've looked online and found no resource that really covers my question. The set up of the server works during the testing but the unit tests are not executed. How would you recommend troubleshooting this? I'm open to all suggestions including changing the approach. Thank you!</p>