Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make testing improvements #3242

Merged
merged 14 commits into from
Apr 29, 2024
2 changes: 1 addition & 1 deletion ignite/metrics/frequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def reset(self) -> None:
self._acc = 0
self._n = 0
self._elapsed = 0.0
super(Frequency, self).reset()
super(Frequency, self).reset() # type: ignore

@reinit__is_reduced
def update(self, output: int) -> None:
Expand Down
2 changes: 1 addition & 1 deletion ignite/metrics/gan/fid.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def reset(self) -> None:
self._test_total = torch.zeros(self._num_features, dtype=torch.float64, device=self._device)
self._num_examples: int = 0

super(FID, self).reset()
super(FID, self).reset() # type: ignore

@reinit__is_reduced
def update(self, output: Sequence[torch.Tensor]) -> None:
Expand Down
2 changes: 1 addition & 1 deletion ignite/metrics/gan/inception_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def reset(self) -> None:
self._prob_total = torch.zeros(self._num_features, dtype=torch.float64, device=self._device)
self._total_kl_d = torch.zeros(self._num_features, dtype=torch.float64, device=self._device)

super(InceptionScore, self).reset()
super(InceptionScore, self).reset() # type: ignore

@reinit__is_reduced
def update(self, output: torch.Tensor) -> None:
Expand Down
12 changes: 12 additions & 0 deletions tests/ignite/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
import ignite.distributed as idist


def pytest_configure(config):
config.addinivalue_line("markers", "distributed: run distributed")
config.addinivalue_line("markers", "multinode_distributed: distributed")
config.addinivalue_line("markers", "tpu: run on tpu")


@pytest.fixture(
params=[
"cpu",
Expand Down Expand Up @@ -492,3 +498,9 @@ def xla_worker(index, fn):
assert ex_.code == 0, "Didn't successfully exit in XLA test"

pyfuncitem.obj = functools.partial(testfunc_wrapper, pyfuncitem.obj)


def pytest_collection_modifyitems(items):
for item in items:
if "distributed" in item.fixturenames:
item.add_marker(pytest.mark.xdist_group("distributed"))
62 changes: 25 additions & 37 deletions tests/ignite/handlers/conftest.py
Original file line number Diff line number Diff line change
@@ -1,58 +1,40 @@
import random
import subprocess
import time
from pathlib import Path
from unittest.mock import Mock

import pytest
import torch
from visdom import Visdom
from visdom.server.build import download_scripts

vd_hostname = None
vd_port = None
vd_server_process = None


@pytest.fixture()
@pytest.fixture(scope="session")
def visdom_server():
# Start Visdom server once and stop it with visdom_server_stop
global vd_hostname, vd_port, vd_server_process

if vd_server_process is None:
import subprocess
import time

from visdom import Visdom
from visdom.server.build import download_scripts

vd_hostname = "localhost"
if not (Path.home() / ".visdom").exists():
(Path.home() / ".visdom").mkdir(exist_ok=True)
download_scripts()
vis = None

vd_hostname = "localhost"
vd_port = random.randint(8089, 8887)

vd_port = 29777
vd_server_process = subprocess.Popen(
["python", "-m", "visdom.server", "--hostname", vd_hostname, "-port", str(vd_port)]
)
time.sleep(2)
for ii in range(5):
try:
time.sleep(1)
vis = Visdom(server=vd_hostname, port=vd_port, raise_exceptions=True)
break
except ConnectionError:
pass

vd_server_process = subprocess.Popen(
["python", "-m", "visdom.server", "--hostname", vd_hostname, "-port", str(vd_port)]
)
time.sleep(5)

vis = Visdom(server=vd_hostname, port=vd_port)
assert vis.check_connection()
vis.close()
continue

assert vis and vis.check_connection()
yield (vd_hostname, vd_port)


@pytest.fixture()
def visdom_server_stop():
yield None

import time

vis.close()
vd_server_process.kill()
time.sleep(2)


@pytest.fixture
Expand Down Expand Up @@ -116,3 +98,9 @@ def get_dummy_model(with_grads=True, with_frozen_layer=False, with_buffer=False)
return model

return get_dummy_model


def pytest_collection_modifyitems(items):
for item in items:
if "visdom_server" in item.fixturenames:
item.add_marker(pytest.mark.timeout(30))
Loading
Loading