0

一旦尝试使用来自 flask_testing 的 LiveServerTestCase 在我的 Flask 应用程序上运行单元测试,我就会收到标题中提到的错误。

这是我的测试文件:

from app import create_app
from flask_testing import LiveServerTestCase

class TestBase(LiveServerTestCase):

    def create_app(self):
        app = create_app()
        app.config.update(LIVESERVER_PORT=8847, TESTING=True)
        return app
    
    def test_app(self):
        self.assertEqual('test', 'test')

这是我使用nose2运行测试时遇到的错误:

AttributeError: Can't pickle local object 'LiveServerTestCase._spawn_live_server.<locals>.worker'

During handling of the above exception, another exception occurred:

AttributeError: 'NoneType' object has no attribute 'terminate'
Internal Error: runTests aborted: 'NoneType' object has no attribute 'terminate'

我真的在网上找不到任何关于这个问题的有用信息,

4

2 回答 2

3

我也遇到了这个问题,想发帖,这样其他人可能有地方开始,不需要像我一样深入调查——

我在这里找到了一个部分答案,至少可以帮助我弄清楚发生了什么: https ://github.com/pytest-dev/pytest-flask/issues/104

显然在OSX上,您需要运行以下代码来将多处理样式切换为 fork 而不是 spawn,这是新的默认值并且与 pickle 不兼容:

multiprocessing.set_start_method("fork")

我正在Windows上开发,所以从我可以看出我有点不走运 - 但​​我有另一台运行 CentOs 的测试服务器,所以为了证明概念,我尝试在那里运行测试,它没有问题!

最后:在另一个问题线程上,我发现以下内容可能会有所帮助,Windows 人员做出了解决方法: https ://github.com/pytest-dev/pytest-flask/issues/54

于 2020-10-23T16:47:09.710 回答
-1

无法真正确定可能是什么原因。但很抱歉,您是否检查过您正在使用的烧瓶版本以及它当前与您的 python 版本的兼容性。

于 2020-10-12T17:50:12.627 回答