Skip to content

Commit 1e84098

Browse files
committed
Fix handling of debug flag when gunicorn is not present
1 parent 8697200 commit 1e84098

File tree

5 files changed

+28
-11
lines changed

5 files changed

+28
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## [Unreleased]
8+
### Fixed
9+
- Fix handling of `--debug` flag when gunicorn is not present ([#44])
810

911
## [1.4.1] - 2020-05-07
12+
### Fixed
1013
- Fix Windows support ([#38])
1114

1215
## [1.4.0] - 2020-05-06
16+
### Changed
1317
- Use gunicorn as a production HTTP server
1418

1519
## [1.3.0] - 2020-04-13
20+
### Added
1621
- Add support for running `python -m functions_framework` ([#31])
22+
23+
### Changed
1724
- Move `functions_framework.cli.cli` to `functions_framework._cli._cli`
1825
- Adjust path handling for robots.txt and favicon.ico ([#33])
1926

@@ -56,6 +63,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
5663
[1.0.1]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.1
5764
[1.0.0]: https://github.com/GoogleCloudPlatform/functions-framework-python/releases/tag/v1.0.0
5865

66+
[#44]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/44
5967
[#38]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/38
6068
[#33]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/33
6169
[#31]: https://github.com/GoogleCloudPlatform/functions-framework-python/pull/31

src/functions_framework/_http/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
class HTTPServer:
1919
def __init__(self, app, debug, **options):
2020
self.app = app
21+
self.debug = debug
2122
self.options = options
2223

23-
if debug:
24+
if self.debug:
2425
self.server_class = FlaskApplication
2526
else:
2627
try:
@@ -31,7 +32,9 @@ def __init__(self, app, debug, **options):
3132
self.server_class = FlaskApplication
3233

3334
def run(self, host, port):
34-
http_server = self.server_class(self.app, host, port, **self.options)
35+
http_server = self.server_class(
36+
self.app, host, port, self.debug, **self.options
37+
)
3538
http_server.run()
3639

3740

src/functions_framework/_http/flask.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414

1515

1616
class FlaskApplication:
17-
def __init__(self, app, host, port, **options):
17+
def __init__(self, app, host, port, debug, **options):
1818
self.app = app
1919
self.host = host
2020
self.port = port
21+
self.debug = debug
2122
self.options = options
2223

2324
def run(self):
24-
self.app.run(self.host, self.port, debug=True, **self.options)
25+
self.app.run(self.host, self.port, debug=self.debug, **self.options)

src/functions_framework/_http/gunicorn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717

1818
class GunicornApplication(gunicorn.app.base.BaseApplication):
19-
def __init__(self, app, host, port, **options):
19+
def __init__(self, app, host, port, debug, **options):
2020
self.options = {
2121
"bind": "%s:%s" % (host, port),
2222
"workers": 1,

tests/test_http.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,15 @@ def test_httpserver(monkeypatch, debug, gunicorn_missing, expected):
7575

7676
wrapper.run(host, port)
7777

78-
assert wrapper.server_class.calls == [pretend.call(app, host, port, **options)]
78+
assert wrapper.server_class.calls == [
79+
pretend.call(app, host, port, debug, **options)
80+
]
7981
assert http_server.run.calls == [pretend.call()]
8082

8183

8284
@pytest.mark.skipif("platform.system() == 'Windows'")
83-
def test_gunicorn_application():
85+
@pytest.mark.parametrize("debug", [True, False])
86+
def test_gunicorn_application(debug):
8487
app = pretend.stub()
8588
host = "1.2.3.4"
8689
port = "1234"
@@ -89,7 +92,7 @@ def test_gunicorn_application():
8992
import functions_framework._http.gunicorn
9093

9194
gunicorn_app = functions_framework._http.gunicorn.GunicornApplication(
92-
app, host, port, **options
95+
app, host, port, debug, **options
9396
)
9497

9598
assert gunicorn_app.app == app
@@ -107,23 +110,25 @@ def test_gunicorn_application():
107110
assert gunicorn_app.load() == app
108111

109112

110-
def test_flask_application():
113+
@pytest.mark.parametrize("debug", [True, False])
114+
def test_flask_application(debug):
111115
app = pretend.stub(run=pretend.call_recorder(lambda *a, **kw: None))
112116
host = pretend.stub()
113117
port = pretend.stub()
114118
options = {"a": pretend.stub(), "b": pretend.stub()}
115119

116120
flask_app = functions_framework._http.flask.FlaskApplication(
117-
app, host, port, **options
121+
app, host, port, debug, **options
118122
)
119123

120124
assert flask_app.app == app
121125
assert flask_app.host == host
122126
assert flask_app.port == port
127+
assert flask_app.debug == debug
123128
assert flask_app.options == options
124129

125130
flask_app.run()
126131

127132
assert app.run.calls == [
128-
pretend.call(host, port, debug=True, a=options["a"], b=options["b"]),
133+
pretend.call(host, port, debug=debug, a=options["a"], b=options["b"]),
129134
]

0 commit comments

Comments
 (0)