test_rtutil: Implement our own nullcontext.

contextlib.nullcontext does not exist in Python 3.6.
This commit is contained in:
Brett Smith 2020-05-13 10:12:08 -04:00
parent 031b660cc6
commit 30e386f645

View file

@ -55,11 +55,15 @@ def new_client():
TICKET_DATA = testutil.RTClient.TICKET_DATA.copy()
return RTClient()
@contextlib.contextmanager
def nullcontext(thing):
yield thing
def new_cache(database=':memory:'):
db = rtutil.RTLinkCache.setup(database)
if db is None:
print("NOTE: did not set up database cache at {}".format(database))
return contextlib.nullcontext(db)
return nullcontext(db)
else:
return contextlib.closing(db)