There are many ways to do tests, often it depends on what framework you use. But, just assuming that you want some form of a formal test framework, you can use pytest.
Step 1, install pytest
$ pip install pytest
Step 2, Format your code. You will test your output according to the return of the function.
def host_is_pingable(x):
#Do your verification logic here... putting the result in a string valid
return valid
Step 3, Now write the tests
def test_answer():
assert host_is_pingable(ip_address) != "some error"
Step 4, run the tests
$ py.test
This is not a unittest, but a boilerplate test framework.
If you want to do unittests, there is a great guide to it here: http://www.onlamp.com/pub/a/python/2004/12/02/tdd_pyunit.html
Update 2019
The unittest introductory guide link is now dead but you can find it archived at WayBackMachine here https://web.archive.org/web/20180121231649/http://www.onlamp.com/pub/a/python/2004/12/02/tdd_pyunit.html