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

Sign up
Appearance settings

Application configuration and context to run pytest? #416

Unanswered
khteh asked this question in Q&A
Discussion options

#149

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:
  • Quart version:
You must be logged in to vote

Replies: 1 comment

Comment options

Stop posting questions as issues, and describe your issue and question rather than dumping a bunch of code.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #415 on February 23, 2025 04:50.

AltStyle によって変換されたページ (->オリジナル) /