Rework toplevel test function to use pytest