我正在使用 Python3、Flask 0.12 和 Pytest 3.0.7。
我有一个类似这样的烧瓶应用程序:
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()
我正在尝试使用 pytest 测试此应用程序,如下所示:
import unittest
import pytest
class TestCheckPriceRequestAPI(unittest.TestCase):
def setUp(self):
self.app = api.app.test_client()
def test_random(self):
pass
当我使用 运行此测试时pytest
,此测试(以及所有其他测试)成功运行,但 pytest 挂起。如何停止正在运行的 pytest 进程(或者可能杀死守护线程)?