Skip to content

Commit

Permalink
Lazy index logs ClobberWarning
Browse files Browse the repository at this point in the history
  • Loading branch information
kenodegard committed Oct 1, 2024
1 parent 8db476d commit 1f533da
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@
import yaml
from binstar_client.commands import remove, show
from binstar_client.errors import NotFound
from conda import __version__ as conda_version
from conda.base.context import context, reset_context
from conda.common.compat import on_linux, on_mac, on_win
from conda.exceptions import ClobberError, CondaError, CondaMultiError, LinkError
from conda.utils import url_path
from conda_index.api import update_index
from packaging.version import Version

from conda_build import __version__, api, exceptions
from conda_build.config import Config
Expand Down Expand Up @@ -69,7 +71,7 @@
)

if TYPE_CHECKING:
from pytest import FixtureRequest, MonkeyPatch
from pytest import CaptureFixture, FixtureRequest, LogCaptureFixture, MonkeyPatch
from pytest_mock import MockerFixture

from conda_build.metadata import MetaData
Expand Down Expand Up @@ -1826,7 +1828,11 @@ def test_downstream_tests(testing_config):


@pytest.mark.sanity
def test_warning_on_file_clobbering(testing_config, capfd):
def test_warning_on_file_clobbering(
testing_config: Config,
capfd: CaptureFixture,
caplog: LogCaptureFixture,
) -> None:
recipe_dir = os.path.join(metadata_dir, "_overlapping_files_warning")

api.build(
Expand All @@ -1844,8 +1850,19 @@ def test_warning_on_file_clobbering(testing_config, capfd):
config=testing_config,
)
# The clobber warning here is raised when creating the test environment for b
out, err = capfd.readouterr()
assert "ClobberWarning" in err
if Version(conda_version) >= Version("24.9.0"):
# conda >=24.9.0
clobber_warning_found = False
for record in caplog.records:
if "ClobberWarning:" in record.message:
clobber_warning_found = True
assert clobber_warning_found
else:
# before the new lazy index added in conda 24.9.0
# see https://github.com/conda/conda/commit/1984b287548a1a526e8258802a6f1fec2a11ecc3
out, err = capfd.readouterr()
assert "ClobberWarning" in err

with pytest.raises((ClobberError, CondaMultiError)):
with env_var("CONDA_PATH_CONFLICT", "prevent", reset_context):
api.build(os.path.join(recipe_dir, "b"), config=testing_config)
Expand Down

0 comments on commit 1f533da

Please sign in to comment.