Move the teardown into a pytest fixture

Move the teardown function into a pytest fixture so it doesn't have to be imported into every test module.