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

Using live_server fixture leads to ScopeMismatch Error #117

Closed
ren1982 opened this issue Mar 6, 2020 · 3 comments
Closed

Using live_server fixture leads to ScopeMismatch Error #117

ren1982 opened this issue Mar 6, 2020 · 3 comments
Labels

Comments

@ren1982
Copy link

ren1982 commented Mar 6, 2020

I'm trying to do the most basic live server test (based on Quickstart and documentation) and despite doing the most bare-bones example possible, I keep getting ScopeMismatch: You tried to access the 'function' scoped fixture 'app' with a 'session' scoped request object, involved factories when running the test.

app.py looks like this:

from flask import Flask


def create_app():
    app = Flask(__name__)

    @app.route('/')
    def main():
        return "<h1>Hello</h1> world"

    return app

conftest.py looks like this

import pytest

from app import create_app


@pytest.fixture
def app():
    app = create_app()
    return app

And finally test_app.py looks like this

import pytest


@pytest.mark.usefixtures('live_server')
def test_server_is_up():
    assert True

(Don't be confused as to why the test is just assert True. I've also tried it with using urllib to open a URL then checking the code but that failed the same way as well. I was hoping doing a basic test that doesn't even use the live server would help resolve the issue but it didn't.)

Python 3.8.1
Flask 1.1.1
pytest==5.3.5
pytest-flask==1.0.0

@nicoddemus
Copy link
Member

Please change your app fixture to:

@pytest.fixture(scope="session")
def app():
    app = create_app()
    return app

Does that fix it?

nicoddemus added a commit that referenced this issue Mar 9, 2020
As #117 shows, it is indeed confusing now that the default `live_server` is session-scoped.
@nicoddemus
Copy link
Member

Btw thanks for noticing this, I have updated the docs: the live_server fixture is now session-scoped by default, but we failed to update the docs. 👍

Closing for now, feel free to follow up with further questions though. 👍

@ren1982
Copy link
Author

ren1982 commented Mar 10, 2020

Thanks for the response!

That got rid of the initial error, but now I'm getting the same error mentioned on #54 . I'll try the workaround/s mentioned in that thread.

textbook added a commit to textbook/flash that referenced this issue Apr 4, 2021
- Travis is no longer on the default dashboard
- Fix pickling error based on pytest-dev/pytest-flask#104
- Fix fixture scoping based on pytest-dev/pytest-flask#117
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants