LiveServer example doesn't work with nose?
(backend)www@backend:/var/www/msgapp/backend/project/tests$ cat test_app.py
import urllib2
from flask.ext.testing import LiveServerTestCase
class MyTest(LiveServerTestCase):
def create_app(self):
app = Flask(__name__)
app.config['TESTING'] = True
# Default port is 5000
app.config['LIVESERVER_PORT'] = 8943
return app
def test_server_is_up_and_running(self):
response = urllib2.urlopen(self.get_server_url())
self.assertEqual(response.code, 200)
(backend)www@backend:/var/www/msgapp/backend/project/tests$ nosetests
E
======================================================================
ERROR: test_server_is_up_and_running (test_app.MyTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/var/www/msgapp/backend/local/lib/python2.7/site-packages/nose/case.py", line 133, in run
self.runTest(result)
File "/var/www/msgapp/backend/local/lib/python2.7/site-packages/nose/case.py", line 151, in runTest
test(result)
File "/var/www/msgapp/backend/local/lib/python2.7/site-packages/flask_testing/utils.py", line 328, in __call__
self._post_teardown()
File "/var/www/msgapp/backend/local/lib/python2.7/site-packages/flask_testing/utils.py", line 358, in _post_teardown
self._process.terminate()
AttributeError: 'NoneType' object has no attribute 'terminate'
----------------------------------------------------------------------
Ran 0 tests in 0.056s
FAILED (errors=1)
Yes, I just encountered the same issue.
Sorry there was no meaningful exception. Without the imported Flask class the create_app method raised an exception but the finally block tried first to terminate the live server process which wasn't started.
I'm getting what seems to be this exact error. I have Flask-Testing 0.4.2 and when I try to run the following:
import urllib2
from flask import Flask
from flask_testing import LiveServerTestCase
class MyTest(LiveServerTestCase):
def create_app(self):
app = Flask(__name__)
app.config['TESTING'] = True
# Default port is 5000
app.config['LIVESERVER_PORT'] = 5000
return app
def test_server_is_up_and_running(self):
response = urllib2.urlopen(self.get_server_url())
self.assertEqual(response.code, 200)
I get
Error
Traceback (most recent call last):
File "C:\Program Files (x86)\JetBrains\PyCharm 3.4.1\helpers\pycharm\nose_helper\case.py", line 47, in run
self.runTest(result)
File "C:\Program Files (x86)\JetBrains\PyCharm 3.4.1\helpers\pycharm\nose_helper\case.py", line 56, in runTest
test(result)
File "C:\Users\Donald\Programming\suspect_tracker\venv\lib\site-packages\flask_testing\utils.py", line 348, in __call__
self._terminate_live_server()
File "C:\Users\Donald\Programming\suspect_tracker\venv\lib\site-packages\flask_testing\utils.py", line 373, in _terminate_live_server
self._process.terminate()
File "C:\Python27\Lib\multiprocessing\process.py", line 137, in terminate
self._popen.terminate()
AttributeError: 'NoneType' object has no attribute 'terminate'
I tried printing self._process and it states that it is < Process(Process-1, initial) >, which I think means that there is an issue with starting the application but I have no clue why or any idea on how to fix it.
Is this a windows problem? I'm using the bare bone set up from the example, but still getting the same error
Same error as @shadefinale @benjamin21st on Windows 7 / python 2.7
The basic LiveServerTestCase worked for me in an ubuntu environment, I think this is Windows related
Appears to be a problem with Windows. Specifically with an incompatibility or edge case in the implementation of the Popen object for this process. @benjamin21st do you have the tools to investigate? Its hard to me to get a hold of a windows machine
@jcomo sure I'll give it a shot later this week. Working on a different project at this moment. Thanks!
Upon initial inspection, the error was initially caused by the EOFError thrown by a library named pickle.
> c:\users\administrator\documents\projects\flask_testing\env\lib\site-packages\flask_testing\utils
.py(545)_terminate_live_server()
-> if self._process:
(Pdb) Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\Lib\multiprocessing\forking.py", line 381, in main
self = load(from_parent)
File "C:\Python27\Lib\pickle.py", line 1384, in load
return Unpickler(file).load()
File "C:\Python27\Lib\pickle.py", line 864, in load
dispatch[key](self)
File "C:\Python27\Lib\pickle.py", line 886, in load_eof
raise EOFError
EOFError
l
540 self._ctx.pop()
541 del self._ctx
542
543 def _terminate_live_server(self):
544 import pdb; pdb.set_trace()
545 -> if self._process:
546 import pdb; pdb.set_trace()
547 self._process.terminate()
I just started using Flask with Python 2.7.13 and have noticed this appears to still be an issue. Is there a work around for running in windows?
Haven't come up with one yet. I'm more than happy to review a PR if someone would like to tackle it. I don't have access to a windows machine so it would be a bit hard for me to reproduce and iterate on.
Ya no issues in Linux, it's all windows and a bit of a pickle. :) Looks more like a python itself needs a PR for this issue. I think it's more the way windows is doing the posix fork for processes.
Believe I just got this same issue trying to run through the Flask-Testing documentation on my Windows 10 machine. Doesn't seem to work whether or not you use nose.
Still no workaround? I got the same issue in Windows 10 and Python 3.7