title: Pytest hangs when a flask server runs another thread
body: <p>I am using Python3, Flask 0.12 and Pytest 3.0.7.</p>
  
  <p>I have a flask app similar to this: </p>
  
  <pre><code>class AppInitializer:
      def __init__(self):
          pass
  
      @staticmethod
      def __function_to_be_refreshed():
          while True:
              try:
                  time.sleep(5)
              except Exception as e:
                  logger.exception(e)
  
  
      def create_app(self):
          daemon_thread = threading.Thread(target=self.__function_to_be_refreshed)
          daemon_thread.daemon = True
          daemon_thread.start()
          atexit.register(daemon_thread.join)
          app_ = Flask(__name__)
          return app_
  
  
  app_initializer = AppInitializer()
  app = app_initializer.create_app()
  </code></pre>
  
  <p>I am trying to test this app using pytest as follows:</p>
  
  <pre><code>import unittest
  
  import pytest
  
  
  class TestCheckPriceRequestAPI(unittest.TestCase):
      def setUp(self):
          self.app = api.app.test_client()
  
      def test_random(self):
          pass
  </code></pre>
  
  <p>When I run this test using <code>pytest</code>, this test (along with all other tests) runs successfully but pytest hangs. How to stop the running pytest process (or maybe kill the daemon thread)? </p>