Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-use app in LiveServerTestCase subclass #115

Open
acidjunk opened this issue Nov 16, 2017 · 2 comments
Open

Re-use app in LiveServerTestCase subclass #115

acidjunk opened this issue Nov 16, 2017 · 2 comments

Comments

@acidjunk
Copy link

First of all: thanks for this excellent testing project :)

I subclassed LiveServerTestCase to do some acceptance testing, and run it in a py.test env. In our case the startup of the app is rather expensive as it needs to connect to a SOAP server with a big wsdl, startup time around 5-6 seconds. Is there a way to reuse the already running app for test in the same TestCase class? Now the app is teared down and (re)started after each test.

@jcomo
Copy link
Collaborator

jcomo commented Nov 20, 2017

I can see the usefulness for a feature like that. I would like it to be controlled by a class level flag that defaults to the current behavior to maintain backwards compatibility and give users of the library the option about whether they want this behavior in their TestCase class or not. If you get a PR together, I can take a look at it.

@acidjunk
Copy link
Author

I now achieved almost what I wanted with an env variabele that let's the developer choose between the LiveCaseServer or the normal flask one, but this makes it more difficult to integrate in the CI, as the server has to be running in background mode (not ideal):

This doesn't use the LiveTestCase server but relies on the user starting it's own:

DISABLE_LIVE_SERVER = True if os.getenv('DISABLE_LIVE_SERVER') else False

class MyLiveTestCase(LiveServerTestCase):
    def create_app(self):
        if DISABLE_LIVE_SERVER:
            return
        return run_application(False)

    def __call__(self, result=None):
        if DISABLE_LIVE_SERVER:
            return super(LiveServerTestCase, self).__call__(result)
        else:
            return super().__call__(result)

    def get_server_url(self):
        """
        Return the url of the test server
        """
        if DISABLE_LIVE_SERVER:
            return 'http://localhost:8080'
        else:
            return super().get_server_url()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants