0

I am getting the error mentioned in the title once trying to run a unittest on my Flask app using LiveServerTestCase from flask_testing.

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:

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,

AcroTom
  • 71
  • 6

2 Answers2

7

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

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:

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!

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

joe
  • 126
  • 4
  • Worked for me, although I had to add a "force=True" argument at the end to avoid the "RuntimeError: context has already been set" error, i.e: multiprocessing.set_start_method("fork", force=True) – skulegirl Sep 09 '22 at 21:13
-1

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.

Otee
  • 90
  • 4
  • Thanks. I thought it might be compatibility issues, but on the Flask documentation it says: "We recommend using the latest version of Python 3. Flask supports Python 3.5 and newer, Python 2.7, and PyPy." Also, I tried versions 3.6 and 3.7 and got the same issue.. – AcroTom Oct 12 '20 at 18:14