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:
|
except NameError:
|
||||||
if is_debug:
|
if is_debug:
|
||||||
traceback.print_exception(*sys.exc_info())
|
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:
|
if app is None:
|
||||||
raise AppImportError("Failed to find application object: %r" % obj)
|
raise AppImportError("Failed to find application object: %r" % obj)
|
||||||
|
|||||||
@ -2,10 +2,26 @@ import functools
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
import platform
|
import platform
|
||||||
|
from wsgiref.validate import validator
|
||||||
|
|
||||||
HOST = "127.0.0.1"
|
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):
|
def requires_mac_ver(*min_version):
|
||||||
"""Decorator raising SkipTest if the OS is Mac OS X and the OS X
|
"""Decorator raising SkipTest if the OS is Mac OS X and the OS X
|
||||||
version if less than min_version.
|
version if less than min_version.
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from gunicorn import util
|
from gunicorn import util
|
||||||
|
from gunicorn.errors import AppImportError
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('test_input, expected', [
|
@pytest.mark.parametrize('test_input, expected', [
|
||||||
@ -45,3 +46,16 @@ def test_warn(capsys):
|
|||||||
util.warn('test warn')
|
util.warn('test warn')
|
||||||
_, err = capsys.readouterr()
|
_, err = capsys.readouterr()
|
||||||
assert '!!! WARNING: test warn' in err
|
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