def mark_cuda_test(inner_f): def f(*args, **kwargs): import pycuda.driver # appears to be idempotent, i.e. no harm in calling it more than once pycuda.driver.init() ctx = make_default_context() try: assert isinstance(ctx.get_device().name(), str) assert isinstance(ctx.get_device().compute_capability(), tuple) assert isinstance(ctx.get_device().get_attributes(), dict) inner_f(*args, **kwargs) finally: ctx.pop() from pycuda.tools import clear_context_caches clear_context_caches() from gc import collect collect() try: from py.test import mark as mark_test except ImportError: return f return mark_test.cuda(f)