conftest.py 332 Bytes
Newer Older
yyy's avatar
yyy committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import pytest
import torch

def clear_gpu_memory():
    '''
    clear GPU memory
    '''
    torch.cuda.empty_cache()
    print("GPU memory cleared.")

@pytest.hookimpl(tryfirst=True, hookwrapper=True)
def pytest_runtest_teardown(item, nextitem):
    '''
    clear GPU memory after each test
    '''
    yield
    clear_gpu_memory()