functions-framework-python | FaaS framework | Serverless library
kandi X-RAY | functions-framework-python Summary
kandi X-RAY | functions-framework-python Summary
FaaS (Function as a service) framework for writing portable Python functions
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Runs the CLI
- Create a WSGI application
- Configure the Flask application
- Decorator for CloudEvent views
- Decorates a CloudEvent view function
- Setup logging
- Wrap the view function
- Create HTTPServer
- Converts a background event into a CloudEvent object
- Splits the resource
- Marshal event data into a dict
- Return True if request payload is a raw payload
- Extract the topic name from the request path
- Converts CloudEvent to a background event
- Split CloudEvent source
functions-framework-python Key Features
functions-framework-python Examples and Code Snippets
Community Discussions
Trending Discussions on functions-framework-python
QUESTION
I try to implement unit tests with Pytest on a Flask app and I have a hard time to do it.
My Flask application uses configuration files on most of the functions (here some_method) to illustrate. So it seems that I should provide a context for each call to any method that I would like to test. It seems that I can achieve it with "with app.app_context():" on each call.
I read the official testing documentation but they talk about creating a client. As I would like to do unit tests, I need to call sub functions which are not top level.
Is there a way to always provide a context without pushing the context manually on each call?
Please find below my current implementation:
main.py
...ANSWER
Answered 2021-Sep-29 at 13:41pytest-flask seems to configure the context on any call.
conftest.py
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install functions-framework-python
Install Docker and the pack tool.
Install Docker and the pack tool.
Build a container from your function using the Functions buildpacks: pack build \ --builder gcr.io/buildpacks/builder:v1 \ --env GOOGLE_FUNCTION_SIGNATURE_TYPE=http \ --env GOOGLE_FUNCTION_TARGET=hello \ my-first-function
Start the built container: docker run --rm -p 8080:8080 my-first-function # Output: Serving function...
Send requests to this function using curl from another terminal window: curl localhost:8080 # Output: Hello World!
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page