[英]Getting a "Can't pickle local object 'LiveServerTestCase'" error when trying to use LiveServerTestCase to test Flask app
I am getting the error mentioned in the title once trying to run a unittest on my Flask app using LiveServerTestCase from flask_testing.一旦尝试使用来自flask_testing的LiveServerTestCase在我的Flask应用程序上运行单元测试,我就会收到标题中提到的错误。
This is my test file:这是我的测试文件:
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')
And this is the error I am getting once running my test using nose2:这是我使用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'
I really couldn't find anything helpful online about this issue,我真的在网上找不到关于这个问题的任何有用的信息,
I also ran into this issue and wanted to post so others might have somewhere to start and not need to sleuth as deep as me--我也遇到了这个问题,想发帖,这样其他人可能有地方可以开始,而不需要像我一样深入——
I found a partial answer here that helped me figure out what was happening at least: https://github.com/pytest-dev/pytest-flask/issues/104我在这里找到了一个部分答案,它至少帮助我弄清楚发生了什么: https : //github.com/pytest-dev/pytest-flask/issues/104
apparently on OSX you need to run the following code to switch the multiprocessing style to fork instead of spawn which is the new default and incompatible with pickle:显然,在OSX 上,您需要运行以下代码将多处理样式切换为 fork 而不是 spawn,后者是新的默认值且与 pickle 不兼容:
multiprocessing.set_start_method("fork")
I'm developing on Windows , so from what I could tell I'm kinda out of luck- but I have another test server running CentOs so for proof of concept I tried running the tests there and it worked without issues!我正在Windows 上开发,所以据我所知,我有点不走运-但是我有另一台运行 CentOs 的测试服务器,所以为了概念证明,我尝试在那里运行测试,并且没有问题!
lastly: On another issue thread I found the following that might help and Windows people make a workaround: https://github.com/pytest-dev/pytest-flask/issues/54最后:在另一个问题线程上,我发现以下内容可能会有所帮助,Windows 人员提出了一种解决方法: https : //github.com/pytest-dev/pytest-flask/issues/54
Can't really identify what could be the cause.无法真正确定可能是什么原因。 But sorry to ask, have you checked the flask version you are using and it's current compatibility with your python version.
但是很抱歉,您是否检查过您正在使用的烧瓶版本以及它与您的python 版本的当前兼容性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.