Repository: Lightning-AI/pytorch-lightning
File: tests/helpers/skipif.py (Python)

Code before:

    if min_gpus:
        conditions.append(torch.cuda.device_count() < min_gpus)
        reasons.append(f"GPUs>={min_gpus}")

    if min_torch:
        torch_version = LooseVersion(get_distribution("torch").version)
        conditions.append(torch_version < LooseVersion(min_torch))
        reasons.append(f"torch>={min_torch}")

    if quant_available:
        _miss_default = 'fbgemm' not in torch.backends.quantized.supported_engines
        conditions.append(not _TORCH_QUANTIZE_AVAILABLE or _miss_default)
        reasons.append("PyTorch quantization is available")

    if not any(conditions):
        return dict(condition=False, reason="Conditions satisfied, going ahead with the test.")

    reasons = [rs for cond, rs in zip(conditions, reasons) if cond]
    return dict(
        condition=any(conditions),
        reason=f"Required: [{' + '.join(reasons)}]",
    )


class LightSkipif(MarkDecorator):
    """
    Light SkipIf wrapper for simple marking specific cases, fully compatible with pytest.mark::

        @LightSkipif(min_torch="0.0")
        def test_wrapper(arg1):
            assert arg1 > 0.0
    """

    def __new__(
        self,
        *args,
        min_gpus: int = 0,
        min_torch: Optional[str] = None,
        quantization_available: bool = False,
        **kwargs
    ):
        custom = skipif_args(
            min_gpus=min_gpus,
            min_torch=min_torch,
            quant_available=quantization_available,
        )
        return pytest.mark.skipif(*args, **custom, **kwargs)


@pytest.mark.skipif(**skipif_args(min_torch="99"))

Review comment (suggestion):
Rename to `LitSkipIf` or `LitSkipif`?

Also, no need to subclass `MarkDecorator`

```suggestion
class LightSkipif:
```

Code after:
            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
            kwargs: native pytest.mark.skipif keyword arguments
        """
        conditions = []
        reasons = []

        if min_gpus:
            conditions.append(torch.cuda.device_count() < min_gpus)
            reasons.append(f"GPUs>={min_gpus}")

        if min_torch:
            torch_version = LooseVersion(get_distribution("torch").version)
            conditions.append(torch_version < LooseVersion(min_torch))
            reasons.append(f"torch>={min_torch}")

        if quantization:
            _miss_default = 'fbgemm' not in torch.backends.quantized.supported_engines
            conditions.append(not _TORCH_QUANTIZE_AVAILABLE or _miss_default)
            reasons.append("missing PyTorch quantization")

        reasons = [rs for cond, rs in zip(conditions, reasons) if cond]
        return pytest.mark.skipif(
            *args,
            condition=any(conditions),
            reason=f"Requires: [{' + '.join(reasons)}]",
            **kwargs,
        )


@SkipIf(min_torch="99")
def test_always_skip():
    exit(1)


@pytest.mark.parametrize("arg1", [0.5, 1.0, 2.0])
@SkipIf(min_torch="0.0")
def test_wrapper(arg1):
    assert arg1 > 0.0