For lighweight testing of RESTful APIs. There is an example of what a rest_test looks like at test/test.py.
Install with
pip3 install git+git://github.com/robknows/rest_test.git#egg=rest_testInclude in your file with
from rest_test import *Write a test like
@test
def can_say_hello():
res = requests.get("http://localhost:8000/hello")
assert_that(res.status_code).is_equal_to(200) # Using the assertpy assertions library
assert_that(res.json()).is_equal_to("hello")If you need to, write code to start and stop your server like
@setup
def start_server():
os.system("./run-my-server &")
@teardown
def stop_server():
os.system("pkill -f \"run-my-server\"")Run all the tests in the file (each marked by @test) by adding the following to the end of the file
exit(main(locals()))Finally, run your the test suite you created with the above steps by running from the command line
python3 my_tests.pyThe exit code will be the number of failed tests (i.e. exit code will be 0 if all tests pass)
-
Create @before_each, @after_each
-
Specify a particular test to run
-
Executable for running all (rest_test)s in a directory (like test/).