mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
Make "failed to find application" more informative (#1648)
Co-Authored-By: Luis Liñán Villafranca <luislivilla@gmail.com> Fixes #1647
This commit is contained in:
parent
120f503f68
commit
6ba2ebe545
@ -363,7 +363,7 @@ def import_app(module):
|
||||
except NameError:
|
||||
if is_debug:
|
||||
traceback.print_exception(*sys.exc_info())
|
||||
raise AppImportError("Failed to find application: %r" % module)
|
||||
raise AppImportError("Failed to find application object %r in %r" % (obj, module))
|
||||
|
||||
if app is None:
|
||||
raise AppImportError("Failed to find application object: %r" % obj)
|
||||
|
||||
@ -2,10 +2,26 @@ import functools
|
||||
import sys
|
||||
import unittest
|
||||
import platform
|
||||
from wsgiref.validate import validator
|
||||
|
||||
HOST = "127.0.0.1"
|
||||
|
||||
|
||||
@validator
|
||||
def app(environ, start_response):
|
||||
"""Simplest possible application object"""
|
||||
|
||||
data = b'Hello, World!\n'
|
||||
status = '200 OK'
|
||||
|
||||
response_headers = [
|
||||
('Content-type', 'text/plain'),
|
||||
('Content-Length', str(len(data))),
|
||||
]
|
||||
start_response(status, response_headers)
|
||||
return iter([data])
|
||||
|
||||
|
||||
def requires_mac_ver(*min_version):
|
||||
"""Decorator raising SkipTest if the OS is Mac OS X and the OS X
|
||||
version if less than min_version.
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
import pytest
|
||||
|
||||
from gunicorn import util
|
||||
from gunicorn.errors import AppImportError
|
||||
|
||||
|
||||
@pytest.mark.parametrize('test_input, expected', [
|
||||
@ -45,3 +46,16 @@ def test_warn(capsys):
|
||||
util.warn('test warn')
|
||||
_, err = capsys.readouterr()
|
||||
assert '!!! WARNING: test warn' in err
|
||||
|
||||
|
||||
def test_import_app():
|
||||
assert util.import_app('support:app')
|
||||
|
||||
with pytest.raises(ImportError) as err:
|
||||
util.import_app('a:app')
|
||||
assert 'No module' in str(err)
|
||||
|
||||
with pytest.raises(AppImportError) as err:
|
||||
util.import_app('support:wrong_app')
|
||||
msg = "Failed to find application object 'wrong_app' in 'support'"
|
||||
assert msg in str(err)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user