Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
added 39 characters in body
Source Link
Adeel
  • 881
  • 8
  • 24

you can use flexmock for that. Say see the example below

Say you have function in file ./myfunc.py

# ./myfunc.py import requests  def function_to_test(..): # some stuff response = requests.post("some"www.url"google.com", data={'dome': 'data'}) return response 

Then the testcase is in ./test_myfunc.py

# ./test_myfunc.py import flexmock as flexmock import myfunc def test_myfunc(): (flexmock(myfunc.requests).should_recieve("post").with_args("/myurl""www.google.com", data={"dome": "data"}).and_return({'some': 'values'})) resp = myfunc.function_to_test() assert resp["some"] == "values" 

Try this, see if this works or let me know for more enhancement/improvement.

you can use flexmock for that. Say you have function in file ./myfunc.py

# ./myfunc.py def function_to_test(..): # some stuff response = requests.post("some.url", data={'dome': 'data'}) return response 

Then the testcase is in ./test_myfunc.py

# ./test_myfunc.py import flexmock as flexmock import myfunc def test_myfunc(): (flexmock(myfunc.requests).should_recieve("post").with_args("/myurl", data={"dome": "data"}).and_return({'some': 'values'})) resp = myfunc.function_to_test() assert resp["some"] == "values" 

Try this, see if this works or let me know for more enhancement/improvement.

you can use flexmock for that. see the example below

Say you have function in file ./myfunc.py

# ./myfunc.py import requests  def function_to_test(..): # some stuff response = requests.post("www.google.com", data={'dome': 'data'}) return response 

Then the testcase is in ./test_myfunc.py

# ./test_myfunc.py import flexmock as flexmock import myfunc def test_myfunc(): (flexmock(myfunc.requests).should_recieve("post").with_args("www.google.com", data={"dome": "data"}).and_return({'some': 'values'})) resp = myfunc.function_to_test() assert resp["some"] == "values" 

Try this, see if this works or let me know for more enhancement/improvement.

Source Link
Adeel
  • 881
  • 8
  • 24

you can use flexmock for that. Say you have function in file ./myfunc.py

# ./myfunc.py def function_to_test(..): # some stuff response = requests.post("some.url", data={'dome': 'data'}) return response 

Then the testcase is in ./test_myfunc.py

# ./test_myfunc.py import flexmock as flexmock import myfunc def test_myfunc(): (flexmock(myfunc.requests).should_recieve("post").with_args("/myurl", data={"dome": "data"}).and_return({'some': 'values'})) resp = myfunc.function_to_test() assert resp["some"] == "values" 

Try this, see if this works or let me know for more enhancement/improvement.