I want to use the LiveServerTestCase class which is provided by flask-testing to test my flask application in combination with Selenium.
I tried implementing the tests the way described in the flask-testing documentation. But documentation on the LiveServerTestCase is very sparse and I always end up getting two instances of my testcases which are executed at the same time.
I ran my tests through Eclipse and PyCharm with the same behaviour.
How do I have to run/configure my tests to only get one testing instance?
This is how I setup my tests:
import unittest
import urllib2
from selenium import webdriver
from CodeLoad import app
from flask_testing import LiveServerTestCase
class flask_tests(LiveServerTestCase):
def create_app(self):
return app
def setUp(self):
self.driver = webdriver.Firefox()
def tearDown(self):
self.driver.close()
def test_0_server_is_up_and_running(self):
response = urllib2.urlopen(self.get_server_url())
self.assertEqual(response.code, 200)
if __name__ == '__main__':
unittest.main()
Create client Fixture We will use a pytest feature called “fixtures” to turn our web app into a Python object we can run tests against. Copy the following code into flask_tests_workshop/test/unit/webapp/__init__.py . This will make client available to all tests under the webapp directory.
Tests are typically located in the tests folder. Tests are functions that start with test_ , in Python modules that start with test_ . Tests can also be further grouped in classes that start with Test .
Flask provides a test client that simulates requests to the application and returns the response data. You should test as much of your code as possible. Code in functions only runs when the function is called, and code in branches, such as if blocks, only runs when the condition is met.
Because of a bug. https://github.com/jarus/flask-testing/issues/33
Try turning DEBUG off
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With