Refactor tests.py