# Path: ecs_scheduler/app.py
# def create():
#     """
#     Start the ECS scheduler daemon and create the flask server.
# 
#     :returns: The flask server instance
#     """
#     try:
#         env.init()
# 
#         _logger.info('ECS Scheduler v%s', env.get_version())
#         app = webapi.create()
# 
#         try:
#             from uwsgidecorators import postfork
#             postfork(functools.partial(_setup_application, app))
#         except ImportError:
#             # NOTE: Flask in debug mode will restart after initial startup
#             # so only setup application state in the main Flask process
#             # to avoid duplicate daemons and other side-effects
#             # see: https://github.com/pallets/werkzeug/blob/master/werkzeug/_reloader.py
#             if werkzeug.serving.is_running_from_reloader() or not app.debug:
#                 _setup_application(app)
# 
#         return app
#     except Exception:
#         _logger.critical('unhandled startup exception', exc_info=True)
#         raise


import logging
import unittest
from unittest.mock import patch, ANY
from ecs_scheduler.app import create
        self, env, queue_class, datacontext, webapi, create_scheduld, reloader,
        exit_register
    ):
        reloader.return_value = True
        webapi.create.return_value.debug = True

        result = create()

        env.init.assert_called_with()
        queue_class.assert_called_with()
        datacontext.load.assert_called_with()
        create_scheduld.assert_called_with(
            queue_class.return_value, datacontext.load.return_value
        )
        webapi.setup.assert_called_with(
            webapi.create.return_value,
            queue_class.return_value,
            datacontext.load.return_value
        )
        create_scheduld.return_value.start.assert_called_with()
        exit_register.assert_called_with(ANY, create_scheduld.return_value)
        self.assertIs(webapi.create.return_value, result)

    def test_skips_setup_if_debug_and_not_reloader(
        self, env, queue_class, datacontext, webapi, create_scheduld, reloader,
        exit_register
    ):
        reloader.return_value = False
        webapi.create.return_value.debug = True


# Path: ecs_scheduler/app.py
# def create():
#     """
#     Start the ECS scheduler daemon and create the flask server.
# 
#     :returns: The flask server instance
#     """
#     try:
#         env.init()
# 
#         _logger.info('ECS Scheduler v%s', env.get_version())
#         app = webapi.create()
# 
#         try:
#             from uwsgidecorators import postfork
#             postfork(functools.partial(_setup_application, app))
#         except ImportError:
#             # NOTE: Flask in debug mode will restart after initial startup
#             # so only setup application state in the main Flask process
#             # to avoid duplicate daemons and other side-effects
#             # see: https://github.com/pallets/werkzeug/blob/master/werkzeug/_reloader.py
#             if werkzeug.serving.is_running_from_reloader() or not app.debug:
#                 _setup_application(app)
# 
#         return app
#     except Exception:
#         _logger.critical('unhandled startup exception', exc_info=True)
#         raise


# Path: test/test_app.py
import logging
import unittest
from unittest.mock import patch, ANY
from ecs_scheduler.app import create

        self, env, queue_class, datacontext, webapi, create_scheduld, reloader,
        exit_register
    ):
        reloader.return_value = True
        webapi.create.return_value.debug = True

        result = create()

        env.init.assert_called_with()
        queue_class.assert_called_with()
        datacontext.load.assert_called_with()
        create_scheduld.assert_called_with(
            queue_class.return_value, datacontext.load.return_value
        )
        webapi.setup.assert_called_with(
            webapi.create.return_value,
            queue_class.return_value,
            datacontext.load.return_value
        )
        create_scheduld.return_value.start.assert_called_with()
        exit_register.assert_called_with(ANY, create_scheduld.return_value)
        self.assertIs(webapi.create.return_value, result)

    def test_skips_setup_if_debug_and_not_reloader(
        self, env, queue_class, datacontext, webapi, create_scheduld, reloader,
        exit_register
    ):
        reloader.return_value = False
        webapi.create.return_value.debug = True


        result = create()