简体   繁体   English

尝试使用 LiveServerTestCase 测试 Flask 应用程序时出现“无法腌制本地对象‘LiveServerTestCase’”错误

[英]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.

相关问题 我们如何使用 Django LiveServerTestCase 和 Selenium 来测试 https url - How can we use Django LiveServerTestCase with Selenium to test https urls Django:为什么我在运行LiveServerTestCase测试时无法获得回溯(如果出现错误)? - Django: why i can't get the tracebacks (in case of error) when i run LiveServerTestCase tests? 使用py.test,LiveServerTestCase后不会重置数据库 - With py.test, database is not reset after LiveServerTestCase 跨 LiveServerTestCase 测试方法保留数据? - Preserve data across LiveServerTestCase test methods? 使LiveServerTestCase在每次测试前都不调用setUp() - Make LiveServerTestCase not to call setUp() before each test Django LiveServerTestCase:在测试时禁用SSL - Django LiveServerTestCase: disable SSL at test-time 将 django.test.LiveServerTestCase 的 live_server_url 与另一个字符串连接时出现 TypeError - TypeError when concatenating django.test.LiveServerTestCase's live_server_url with another string 试图将我的 CNN 模型保存在 Pickle 文件中,但出现 TypeError: can&#39;t pickle _thread._local objects - Trying to save my CNN model in a Pickle file but getting a TypeError: can't pickle _thread._local objects 如何解决使用pandaralel时“无法腌制本地对象”错误 - How to solve "Can't pickle local object" error in using pandarallel PyTorch model 保存错误:“无法腌制本地对象” - PyTorch model saving error: "Can't pickle local object"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM