This is the way they do it on the official Python Neo4j Driver, it should probably be considered a “good example,” given where it comes from.
class ServerTestCase(TestCase):
""" Base class for test cases that use a remote server.
"""
known_hosts = KNOWN_HOSTS
known_hosts_backup = known_hosts + ".backup"
def setUp(self):
if isfile(self.known_hosts):
if isfile(self.known_hosts_backup):
remove(self.known_hosts_backup)
rename(self.known_hosts, self.known_hosts_backup)
def tearDown(self):
if isfile(self.known_hosts_backup):
if isfile(self.known_hosts):
remove(self.known_hosts)
rename(self.known_hosts_backup, self.known_hosts)
: https://github.com/neo4j/neo4j-python-driver/blob/1.1/test/util.py