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

Code before:
        @pytest.mark.skipif(**create_skipif(min_torch="99"))
        def test_any_func(...):
            ...

    >>> from pprint import pprint
    >>> pprint(skipif_args(min_torch="99", min_gpus=0))
    {'condition': True, 'reason': 'Required: [torch>=99]'}
    >>> pprint(skipif_args(min_torch="0.0", min_gpus=0))  # doctest: +NORMALIZE_WHITESPACE
    {'condition': False, 'reason': 'Conditions satisfied, going ahead with the test.'}
    """
    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 avail_quant:
        _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)}]",)


@pytest.mark.skipif(**skipif_args(min_torch="99"))
def test_always_skip():
    exit(1)


@pytest.mark.skipif(**skipif_args(min_torch="0.0"))
def test_always_pass():
    assert True


Review comment (suggestion):
```suggestion
        reasons.append("pytorch_quantization=available")
```

Code after:
        @pytest.mark.skipif(**create_skipif(min_torch="99"))
        def test_any_func(...):
            ...

    >>> from pprint import pprint
    >>> pprint(skipif_args(min_torch="99", min_gpus=0))
    {'condition': True, 'reason': 'Required: [torch>=99]'}
    >>> pprint(skipif_args(min_torch="0.0", min_gpus=0))  # doctest: +NORMALIZE_WHITESPACE
    {'condition': False, 'reason': 'Conditions satisfied, going ahead with the test.'}
    """
    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 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)}]",)


@pytest.mark.skipif(**skipif_args(min_torch="99"))
def test_always_skip():
    exit(1)


@pytest.mark.skipif(**skipif_args(min_torch="0.0"))
def test_always_pass():
    assert True