Skip to content

Commit

Permalink
Refactor: skipif for Windows 2/n (#6268)
Browse files Browse the repository at this point in the history
* win

* isort

* flake8
  • Loading branch information
Borda authored Mar 2, 2021
1 parent 22985d2 commit 0f9134e
Show file tree
Hide file tree
Showing 54 changed files with 119 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Recurent events
name: Recurrent events

# https://jasonet.co/posts/scheduled-actions/
# https://git.luolix.topmunity/t/distinct-job-for-each-schedule/17811/2
Expand Down
7 changes: 1 addition & 6 deletions pytorch_lightning/profiler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,7 @@ def custom_processing_step(self, data):
"""

from pytorch_lightning.profiler.profilers import (
AdvancedProfiler,
BaseProfiler,
PassThroughProfiler,
SimpleProfiler,
)
from pytorch_lightning.profiler.profilers import AdvancedProfiler, BaseProfiler, PassThroughProfiler, SimpleProfiler
from pytorch_lightning.profiler.pytorch import PyTorchProfiler

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion tests/accelerators/test_accelerator_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from pytorch_lightning.plugins.environments import ClusterEnvironment, SLURMEnvironment, TorchElasticEnvironment
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from tests.helpers.boring_model import BoringModel
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf


def test_accelerator_choice_cpu(tmpdir):
Expand Down
5 changes: 2 additions & 3 deletions tests/accelerators/test_ddp.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import platform
from unittest.mock import patch

import pytest
Expand All @@ -21,7 +20,7 @@
from pytorch_lightning import Trainer
from tests.accelerators import ddp_model, DDPLauncher
from tests.helpers.boring_model import BoringModel
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf
from tests.utilities.distributed import call_training_script

CLI_ARGS = '--max_epochs 1 --gpus 2 --accelerator ddp'
Expand Down Expand Up @@ -83,7 +82,7 @@ def test_cli_to_pass(tmpdir, args=None):
return '1'


@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
@RunIf(skip_windows=True)
@pytest.mark.skipif(torch.cuda.is_available(), reason="test doesn't requires GPU machine")
def test_torch_distributed_backend_env_variables(tmpdir):
"""
Expand Down
2 changes: 1 addition & 1 deletion tests/accelerators/test_ddp_spawn.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from pytorch_lightning.trainer.states import TrainerState
from tests.helpers import BoringModel
from tests.helpers.datamodules import ClassifDataModule
from tests.helpers.runif import RunIf
from tests.helpers.simple_models import ClassificationModel
from tests.helpers.skipif import RunIf


@RunIf(min_gpus=2)
Expand Down
2 changes: 1 addition & 1 deletion tests/accelerators/test_dp.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from pytorch_lightning.core import memory
from tests.helpers import BoringModel
from tests.helpers.datamodules import ClassifDataModule
from tests.helpers.runif import RunIf
from tests.helpers.simple_models import ClassificationModel
from tests.helpers.skipif import RunIf

PRETEND_N_OF_GPUS = 16

Expand Down
6 changes: 3 additions & 3 deletions tests/callbacks/test_early_stopping.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
import os
import pickle
import sys
from unittest import mock

import cloudpickle
Expand All @@ -27,6 +26,7 @@
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from tests.helpers import BoringModel
from tests.helpers.datamodules import ClassifDataModule
from tests.helpers.runif import RunIf
from tests.helpers.simple_models import ClassificationModel


Expand Down Expand Up @@ -374,13 +374,13 @@ def on_train_end(self) -> None:
3,
'ddp_cpu',
2,
marks=pytest.mark.skipif(sys.platform == "win32", reason="DDP not available on windows")),
marks=RunIf(skip_windows=True)),
pytest.param([EarlyStopping(monitor='cba', patience=3),
EarlyStopping(monitor='abc')],
3,
'ddp_cpu',
2,
marks=pytest.mark.skipif(sys.platform == "win32", reason="DDP not available on windows")),
marks=RunIf(skip_windows=True)),
],
)
def test_multiple_early_stopping_callbacks(callbacks, expected_stop_epoch, accelerator, num_processes, tmpdir):
Expand Down
2 changes: 1 addition & 1 deletion tests/callbacks/test_gpu_stats_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from pytorch_lightning.trainer.states import TrainerState
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from tests.helpers import BoringModel
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf


@RunIf(min_gpus=1)
Expand Down
8 changes: 3 additions & 5 deletions tests/callbacks/test_pruning.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import platform
from collections import OrderedDict
from logging import INFO
from unittest import mock
Expand All @@ -27,7 +26,7 @@
from pytorch_lightning.callbacks import ModelPruning
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from tests.helpers import BoringModel
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf


class TestModel(BoringModel):
Expand Down Expand Up @@ -169,13 +168,12 @@ def test_pruning_callback_ddp(tmpdir, use_global_unstructured, parameters_to_pru
)


@RunIf(min_gpus=2)
@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
@RunIf(min_gpus=2, skip_windows=True)
def test_pruning_callback_ddp_spawn(tmpdir):
train_with_pruning_callback(tmpdir, use_global_unstructured=True, accelerator="ddp_spawn", gpus=2)


@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
@RunIf(skip_windows=True)
def test_pruning_callback_ddp_cpu(tmpdir):
train_with_pruning_callback(tmpdir, parameters_to_prune=True, accelerator="ddp_cpu", num_processes=2)

Expand Down
2 changes: 1 addition & 1 deletion tests/callbacks/test_quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
from pytorch_lightning.metrics.functional.mean_relative_error import mean_relative_error
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from tests.helpers.datamodules import RegressDataModule
from tests.helpers.runif import RunIf
from tests.helpers.simple_models import RegressionModel
from tests.helpers.skipif import RunIf


@pytest.mark.parametrize("observe", ['average', pytest.param('histogram', marks=RunIf(min_torch="1.5"))])
Expand Down
6 changes: 2 additions & 4 deletions tests/callbacks/test_stochastic_weight_avg.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import platform
from unittest import mock

import pytest
Expand All @@ -24,7 +23,7 @@
from pytorch_lightning.utilities import _TORCH_GREATER_EQUAL_1_6
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from tests.helpers import BoringModel, RandomDataset
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf

if _TORCH_GREATER_EQUAL_1_6:
from pytorch_lightning.callbacks import StochasticWeightAveraging
Expand Down Expand Up @@ -128,8 +127,7 @@ def test_swa_callback_ddp_spawn(tmpdir):
train_with_swa(tmpdir, accelerator="ddp_spawn", gpus=2)


@RunIf(min_torch="1.6.0")
@pytest.mark.skipif(platform.system() == "Windows", reason="ddp_cpu is not available on Windows")
@RunIf(min_torch="1.6.0", skip_windows=True)
def test_swa_callback_ddp_cpu(tmpdir):
train_with_swa(tmpdir, accelerator="ddp_cpu", num_processes=2)

Expand Down
6 changes: 2 additions & 4 deletions tests/checkpointing/test_torch_saving.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import platform

import pytest
import torch

from pytorch_lightning import Trainer
from tests.helpers import BoringModel
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf


def test_model_torch_save(tmpdir):
Expand All @@ -39,7 +37,7 @@ def test_model_torch_save(tmpdir):
trainer = torch.load(temp_path)


@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
@RunIf(skip_windows=True)
def test_model_torch_save_ddp_cpu(tmpdir):
"""Test to ensure torch save does not fail for model and trainer using cpu ddp."""
model = BoringModel()
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_datamodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from pytorch_lightning.utilities.model_helpers import is_overridden
from tests.helpers import BoringDataModule, BoringModel
from tests.helpers.datamodules import ClassifDataModule
from tests.helpers.runif import RunIf
from tests.helpers.simple_models import ClassificationModel
from tests.helpers.skipif import RunIf
from tests.helpers.utils import reset_seed, set_random_master_port


Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

from pytorch_lightning.core.decorators import auto_move_data
from tests.helpers import BoringModel
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf


@RunIf(min_gpus=1)
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pytorch_lightning.utilities.exceptions import MisconfigurationException
from tests.helpers import BoringModel
from tests.helpers.advanced_models import ParityModuleRNN
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf


class EmptyModule(LightningModule):
Expand Down
5 changes: 2 additions & 3 deletions tests/core/test_metric_result_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys

import pytest
import torch
import torch.distributed as dist
import torch.multiprocessing as mp

import tests.helpers.utils as tutils
from pytorch_lightning.core.step_result import Result
from pytorch_lightning.metrics import Metric
from tests.helpers.runif import RunIf


class DummyMetric(Metric):
Expand Down Expand Up @@ -90,7 +89,7 @@ def _ddp_test_fn(rank, worldsize):
assert epoch_expected[k] == epoch_log[k]


@pytest.mark.skipif(sys.platform == "win32", reason="DDP not available on windows")
@RunIf(skip_windows=True)
def test_result_reduce_ddp():
"""Make sure result logging works with DDP"""
tutils.reset_seed()
Expand Down
5 changes: 2 additions & 3 deletions tests/core/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import random
import sys
from pathlib import Path

import pytest
Expand All @@ -26,7 +25,7 @@
from pytorch_lightning.core.step_result import Result
from pytorch_lightning.trainer.states import TrainerState
from tests.helpers import BoringDataModule, BoringModel
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf


def _setup_ddp(rank, worldsize):
Expand All @@ -49,7 +48,7 @@ def _ddp_test_fn(rank, worldsize, result_cls: Result):


@pytest.mark.parametrize("result_cls", [Result])
@pytest.mark.skipif(sys.platform == "win32", reason="DDP not available on windows")
@RunIf(skip_windows=True)
def test_result_reduce_ddp(result_cls):
"""Make sure result logging works with DDP"""
tutils.reset_seed()
Expand Down
6 changes: 2 additions & 4 deletions tests/deprecated_api/test_remove_1-4.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test deprecated functionality which will be removed in v1.4.0"""
import sys

import pytest
import torch
Expand All @@ -28,7 +27,7 @@
from pytorch_lightning.plugins.environments import TorchElasticEnvironment
from tests.deprecated_api import _soft_unimport_module
from tests.helpers import BoringModel
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf


def test_v1_4_0_deprecated_trainer_attributes():
Expand Down Expand Up @@ -178,8 +177,7 @@ def configure_ddp(self):
assert isinstance(self.model.module, LightningDistributedModule)


@RunIf(min_gpus=2)
@pytest.mark.skipif(sys.platform == "win32", reason="DDP not available on windows")
@RunIf(min_gpus=2, skip_windows=True)
def test_v1_4_0_deprecated_lightning_distributed_data_parallel(tmpdir):
model = BoringModel()
trainer = Trainer(
Expand Down
16 changes: 15 additions & 1 deletion tests/helpers/skipif.py → tests/helpers/runif.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from distutils.version import LooseVersion
from typing import Optional

Expand All @@ -31,13 +32,22 @@ def test_wrapper(arg1):
assert arg1 > 0.0
"""

def __new__(self, *args, min_gpus: int = 0, min_torch: Optional[str] = None, quantization: bool = False, **kwargs):
def __new__(
self,
*args,
min_gpus: int = 0,
min_torch: Optional[str] = None,
quantization: bool = False,
skip_windows: bool = False,
**kwargs
):
"""
Args:
args: native pytest.mark.skipif arguments
min_gpus: min number of gpus required to run test
min_torch: minimum pytorch version to run test
quantization: if `torch.quantization` package is required to run test
skip_windows: skip test for Windows platform (typically fo some limited torch functionality)
kwargs: native pytest.mark.skipif keyword arguments
"""
conditions = []
Expand All @@ -57,6 +67,10 @@ def __new__(self, *args, min_gpus: int = 0, min_torch: Optional[str] = None, qua
conditions.append(not _TORCH_QUANTIZE_AVAILABLE or _miss_default)
reasons.append("missing PyTorch quantization")

if skip_windows:
conditions.append(sys.platform == "win32")
reasons.append("unimplemented on Windows")

reasons = [rs for cond, rs in zip(conditions, reasons) if cond]
return pytest.mark.skipif(
*args,
Expand Down
4 changes: 2 additions & 2 deletions tests/loggers/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import inspect
import os
import pickle
import platform
from unittest import mock
from unittest.mock import ANY

Expand All @@ -34,6 +33,7 @@
from pytorch_lightning.loggers.base import DummyExperiment
from pytorch_lightning.trainer.states import TrainerState
from tests.helpers import BoringModel
from tests.helpers.runif import RunIf
from tests.loggers.test_comet import _patch_comet_atexit
from tests.loggers.test_mlflow import mock_mlflow_run_creation

Expand Down Expand Up @@ -332,7 +332,7 @@ def on_train_batch_start(self, trainer, pl_module, batch, batch_idx, dataloader_
TestTubeLogger,
]
)
@pytest.mark.skipif(platform.system() == "Windows", reason="Distributed training is not supported on Windows")
@RunIf(skip_windows=True)
def test_logger_created_on_rank_zero_only(tmpdir, monkeypatch, logger_class):
""" Test that loggers get replaced by dummy loggers on global rank > 0"""
_patch_comet_atexit(monkeypatch)
Expand Down
2 changes: 1 addition & 1 deletion tests/metrics/test_composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from pytorch_lightning.metrics.compositional import CompositionalMetric
from pytorch_lightning.metrics.metric import Metric
from tests.helpers.skipif import RunIf
from tests.helpers.runif import RunIf


class DummyMetric(Metric):
Expand Down
Loading

0 comments on commit 0f9134e

Please sign in to comment.