Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Application configuration and context to run pytest? #411

Copy link
Copy link
@khteh

Description

@khteh
Issue body actions
import pytest, sys, asyncio
from hypercorn.config import Config
from hypercorn.asyncio import serve
from os.path import dirname, join, abspath
from src.app import create_app
#from src.main import app
from quart_cors import cors
sys.path.insert(0, abspath(join(dirname(__file__), '../src')))
from common.Authentication import Authentication
pytest_plugins = ('pytest_asyncio',)
@pytest.fixture
async def app_context():
    config = Config()
    config.bind = ["localhost:4433"]
    config.insecure_bind = ["localhost:8080"]
    config.worker_class = "asyncio"
    config.alt_svc_headers = ["h3=\":443\"; ma=3600, h3-29=\":443\"; ma=3600"]
    config.loglevel = "DEBUG"
    config.quic_bind = ["localhost:4433"]
    app = create_app()
    app = cors(app, allow_credentials=True, allow_origin="https://localhost:4433")
    asyncio.run(serve(app, config))
    async with app.app_context():
       yield

@pytest.mark.asyncio
async def test_tokengeneration_pass(app_context):
    """ JWT token generation should pass with valid user input parameter """
    token = Authentication.generate_token("test_user")
    assert type(token) is str
    assert token != ""

Error:

E           RuntimeError: Not within an app context

Environment:

  • Python version: 3.12.7
  • Quart version:
$ pipenv graph|grep -i quart
quart-cors==0.8.0
└── Quart 
quart-flask-patch==0.3.0
└── Quart 
Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.