Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does flask-testing spawn two test instances?

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()
like image 781
JaVaEs Avatar asked Nov 10 '13 14:11

JaVaEs


People also ask

How do you run a unit test in a Flask?

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.

Where do I put tests in the Flask app?

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 .

What is Flask Test_client?

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.


1 Answers

Because of a bug. https://github.com/jarus/flask-testing/issues/33

Try turning DEBUG off

like image 155
Philip Pearl Avatar answered Sep 17 '22 16:09

Philip Pearl