So I want to start using tests with pytest in my python programs.
EDIT: I'm only trying to test the response because it seemed like the easiest thing to test. I now understand that there are multiple ways to test the response, but I'm more looking to just get a general grip on building tests and using them.
I'm starting by testing if the correct response happens when I call a page using requests.
Like so:
**main.py**
def get_page(search_url):
page = requests.get(search_url)
return page
url = "https://www.google.com/search?q=weather+results&oq=weather+results&aqs=chrome..69i57.4626j0j1&sourceid=chrome&ie=UTF-8"
get_page(url)
Here is the test code I made to test the response. This is the first test I've ever written.
**test_main.py**
from main import get_page
def test_page_response():
test_url = "https://www.google.com/search?q=weather+results&oq=weather+results&aqs=chrome..69i57.4626j0j1&sourceid=chrome&ie=UTF-8"
assert str(get_page(test_url2)) == "<Response [200]>"
Am I doing this right? When I take out the url to break it and trigger a test, it shows me a ton of text. Sure, it's the error in it's full glory, but isn't testing supposed to make this simpler to read and understand what broke?
This leads me to believe I'm going about this the wrong way.
EDIT 2: Here's the output: http://pastebin.com/kTgc5bsR