8000 fix: Add functools.wraps decorator (#179) · jrmfg/functions-framework-python@f2285f9 · GitHub
[go: up one dir, main page]

Skip to content

Commit f2285f9

Browse files
svleeuwenanniefu
andauthored
fix: Add functools.wraps decorator (GoogleCloudPlatf 10000 orm#179)
* fix: Add functools.wraps decorator (GoogleCloudPlatform#178) To make sure function attributes are copied to `_http_view_func_wrapper` Co-authored-by: Annie Fu <16651409+anniefu@users.noreply.github.com>
1 parent 6c9ce8c commit f2285f9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/functions_framework/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def setup_logging():
9595

9696

9797
def _http_view_func_wrapper(function, request):
98+
@functools.wraps(function)
9899
def view_func(path):
99100
return function(request._get_current_object())
100101

tests/test_view_functions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ def test_http_view_func_wrapper():
3333
assert function.calls == [pretend.call(request_object)]
3434

3535

36+
def test_http_view_func_wrapper_attribute_copied():
37+
def function(_):
38+
pass
39+
40+
function.attribute = "foo"
41+
view_func = functions_framework._http_view_func_wrapper(function, pretend.stub())
42+
43+
assert view_func.__name__ == "function"
44+
assert view_func.attribute == "foo"
45+
46+
3647
def test_event_view_func_wrapper(monkeypatch):
3748
data = pretend.stub()
3849
json = {

0 commit comments

Comments
 (0)
0