I have a small flask app that has the code below. Please note that I have removed a great deal of code to simply my question. If anything needed re-adding or missing, let me know.
1 @app.route("/app/data/", methods=['POST'])
2 def methodpost():
3
4 if 'Content-Type' in request.headers and request.headers['Content-Type'] == 'application/json':
5
6 #some_code
7 #some_more_code
8
9 if not any(['unittest' or 'discover' in arg for arg in sys.argv]):
10
11 #code_calls_external_stuff
12 #more_code
13
14
15 return msg
16
17
18 app.run(host=0.0.0.0, debug=debug, port=5000)
When I do a cURL to it using the following:
curl -X POST "localhost:5000/app/data/" -H "Content-Type: application/json" -d @jsonBody
It does not go into LINE-11 and LINE-12.
However, when I modify LINE-9 to the following:
----FROM:----
if not any(['unittest' or 'discover' in arg for arg in sys.argv]):
----TO:----
if not any(['unittest' in arg for arg in sys.argv]):
then it works and calls LINE-11 and LINE-12. The above was only added so I can run UnitTest and Tox while the app is not running because i did not want to make external calls... Is there a way to get around it while keeping the code as it is.