Repository: huggingface/diffusers
File: tests/pipelines/test_pipelines.py (Python)

Code before:
                    # Check for `model_ext` and `variant`.
                    model_ext = ".safetensors" if use_safetensors else ".bin"
                    unexpected_ext = ".bin" if use_safetensors else ".safetensors"
                    model_files = [f for f in files if f.endswith(model_ext)]
                    assert not any(f.endswith(unexpected_ext) for f in files)
                    assert all(variant in f for f in model_files if f.endswith(model_ext) and variant is not None)

    @pytest.mark.xfail(condition=is_transformers_version(">", "4.56.2"), reason="Some import error", strict=True)
    def test_download_legacy_variants_with_sharded_ckpts_raises_warning(self):
        repo_id = "hf-internal-testing/tiny-stable-diffusion-pipe-variants-all-kinds"
        logger = logging.get_logger("diffusers.pipelines.pipeline_utils")
        deprecated_warning_msg = "Warning: The repository contains sharded checkpoints for variant"

        with CaptureLogger(logger) as cap_logger:
            with tempfile.TemporaryDirectory() as tmpdirname:
                local_repo_id = snapshot_download(repo_id, cache_dir=tmpdirname)

                _ = DiffusionPipeline.from_pretrained(
                    local_repo_id,
                    safety_checker=None,
                    variant="fp16",
                    use_safetensors=True,
                )
        assert deprecated_warning_msg in str(cap_logger), "Deprecation warning not found in logs"

    @pytest.mark.xfail(condition=is_transformers_version(">", "4.56.2"), reason="Some import error", strict=True)
    def test_download_safetensors_only_variant_exists_for_model(self):
        variant = None
        use_safetensors = True

        # text encoder is missing no variant weights, so the following can't work
        with tempfile.TemporaryDirectory() as tmpdirname:
            with self.assertRaises(OSError) as error_context:
                tmpdirname = StableDiffusionPipeline.from_pretrained(
                    "hf-internal-testing/stable-diffusion-broken-variants",
                    cache_dir=tmpdirname,
                    variant=variant,
                    use_safetensors=use_safetensors,
                )
            assert "Could not find the necessary `safetensors` weights" in str(error_context.exception)

        # text encoder has fp16 variants so we can load it
        with tempfile.TemporaryDirectory() as tmpdirname:
            tmpdirname = StableDiffusionPipeline.download(
                "hf-internal-testing/stable-diffusion-broken-variants",
                use_safetensors=use_safetensors,
                cache_dir=tmpdirname,
                variant="fp16",
            )
            all_root_files = [t[-1] for t in os.walk(tmpdirname)]
            files = [item for sublist in all_root_files for item in sublist]

Review comment (bug):
Perhaps I am missing something, but it appears that this test (and `test_download_safetensors_variant_does_not_exist_for_model` below) are still marked as failed rather than xfailed in the CI:
```
FAILED tests/pipelines/test_pipelines.py::DownloadTests::test_download_safetensors_only_variant_exists_for_model
FAILED tests/pipelines/test_pipelines.py::DownloadTests::test_download_safetensors_variant_does_not_exist_for_model
```
Is this expected?

Code after:
                    # Check for `model_ext` and `variant`.
                    model_ext = ".safetensors" if use_safetensors else ".bin"
                    unexpected_ext = ".bin" if use_safetensors else ".safetensors"
                    model_files = [f for f in files if f.endswith(model_ext)]
                    assert not any(f.endswith(unexpected_ext) for f in files)
                    assert all(variant in f for f in model_files if f.endswith(model_ext) and variant is not None)

    @pytest.mark.xfail(condition=is_transformers_version(">", "4.56.2"), reason="Some import error", strict=False)
    def test_download_legacy_variants_with_sharded_ckpts_raises_warning(self):
        repo_id = "hf-internal-testing/tiny-stable-diffusion-pipe-variants-all-kinds"
        logger = logging.get_logger("diffusers.pipelines.pipeline_utils")
        deprecated_warning_msg = "Warning: The repository contains sharded checkpoints for variant"

        with CaptureLogger(logger) as cap_logger:
            with tempfile.TemporaryDirectory() as tmpdirname:
                local_repo_id = snapshot_download(repo_id, cache_dir=tmpdirname)

                _ = DiffusionPipeline.from_pretrained(
                    local_repo_id,
                    safety_checker=None,
                    variant="fp16",
                    use_safetensors=True,
                )
        assert deprecated_warning_msg in str(cap_logger), "Deprecation warning not found in logs"

    def test_download_safetensors_only_variant_exists_for_model(self):
        variant = None
        use_safetensors = True

        # text encoder is missing no variant weights, so the following can't work
        with tempfile.TemporaryDirectory() as tmpdirname:
            with self.assertRaises(OSError) as error_context:
                tmpdirname = StableDiffusionPipeline.from_pretrained(
                    "hf-internal-testing/stable-diffusion-broken-variants",
                    cache_dir=tmpdirname,
                    variant=variant,
                    use_safetensors=use_safetensors,
                )
            assert "Could not find the necessary `safetensors` weights" in str(error_context.exception)

        # text encoder has fp16 variants so we can load it
        with tempfile.TemporaryDirectory() as tmpdirname:
            tmpdirname = StableDiffusionPipeline.download(
                "hf-internal-testing/stable-diffusion-broken-variants",
                use_safetensors=use_safetensors,
                cache_dir=tmpdirname,
                variant="fp16",
            )
            all_root_files = [t[-1] for t in os.walk(tmpdirname)]
            files = [item for sublist in all_root_files for item in sublist]
            # None of the downloaded files should be a non-variant file even if we have some here: