Skip to content

Commit bed0860

Browse files
Tests: improve memory usage (#1147)
1 parent 494de20 commit bed0860

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/conftest.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import gc
2+
13
import pytest
24
import torch
35

@@ -20,6 +22,13 @@ def pytest_runtest_call(item):
2022
raise
2123

2224

25+
@pytest.hookimpl(trylast=True)
26+
def pytest_runtest_teardown(item, nextitem):
27+
gc.collect()
28+
if torch.cuda.is_available():
29+
torch.cuda.empty_cache()
30+
31+
2332
@pytest.fixture(scope="session")
2433
def requires_cuda() -> bool:
2534
cuda_available = torch.cuda.is_available()

0 commit comments

Comments
 (0)