Skip to content

Commit 736a241

Browse files
committed
Updated test_gpu_memory.py
1 parent 3f23271 commit 736a241

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tests/ignite/contrib/metrics/test_gpu_memory.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import sys
2+
13
import torch
24

35
from ignite.contrib.metrics import GpuMemory
@@ -7,11 +9,7 @@
79

810
@pytest.fixture
911
def no_site_packages():
10-
try:
11-
import pynvml
12-
except ImportError:
13-
yield "no_site_packages"
14-
return
12+
import pynvml
1513
import sys
1614
assert 'pynvml' in sys.modules
1715
pynvml_module = sys.modules['pynvml']
@@ -23,20 +21,22 @@ def no_site_packages():
2321
sys.modules['pynvml'] = pynvml_module
2422

2523

24+
@pytest.mark.skipif(sys.version[0] == "2", reason="No pynvml for python 2.7")
2625
def test_no_pynvml_package(no_site_packages):
2726

2827
with pytest.raises(RuntimeError, match="This contrib module requires pynvml to be installed."):
2928
GpuMemory()
3029

3130

32-
@pytest.mark.skipif(torch.cuda.is_available(), reason="Skip if has GPU")
31+
@pytest.mark.skipif(sys.version[0] == "2" or torch.cuda.is_available(), reason="No pynvml for python 2.7")
3332
def test_no_gpu():
3433

3534
with pytest.raises(RuntimeError, match="This contrib module requires available GPU"):
3635
GpuMemory()
3736

3837

39-
@pytest.mark.skipif(torch.cuda.is_available(), reason="Skip if has GPU")
38+
@pytest.mark.skipif(sys.version[0] == "2" or not (torch.cuda.is_available()),
39+
reason="No pynvml for python 2.7 and no GPU")
4040
def test_gpu_mem_consumption():
4141

4242
gpu_mem = GpuMemory()

0 commit comments

Comments
 (0)