From c91fbed30adae86aa3be3d0db69ccbba0db20ba5 Mon Sep 17 00:00:00 2001 From: Ken Odegard Date: Thu, 23 May 2024 13:07:12 +0200 Subject: [PATCH] Add test --- conda_build/build.py | 5 +++-- conda_build/deprecations.py | 13 +++++++++++-- news/3192-deprecate-testing-recipes | 19 +++++++++++++++++++ tests/test_build.py | 14 +++++++++++++- 4 files changed, 46 insertions(+), 5 deletions(-) create mode 100644 news/3192-deprecate-testing-recipes diff --git a/conda_build/build.py b/conda_build/build.py index 450535b889..7d12a9acd8 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -2833,9 +2833,10 @@ def warn_on_use_of_SRC_DIR(metadata): "3.16.0", "24.7.0", addendum=( - "Test built packages instead, not recipes. E.g., " - "`conda build --test package.conda` instead of `conda build --test recipe/`." + "Test built packages instead, not recipes " + "(e.g., `conda build --test package` instead of `conda build --test recipe/`)." ), + deprecation_type=FutureWarning, # we need to warn users, not developers ) def _construct_metadata_for_test_from_recipe(recipe_dir, config): config.need_cleanup = False diff --git a/conda_build/deprecations.py b/conda_build/deprecations.py index f691b5192d..cf87b4f25c 100644 --- a/conda_build/deprecations.py +++ b/conda_build/deprecations.py @@ -86,6 +86,7 @@ def __call__( *, addendum: str | None = None, stack: int = 0, + deprecation_type: type[Warning] = DeprecationWarning, ) -> Callable[[Callable[P, T]], Callable[P, T]]: """Deprecation decorator for functions, methods, & classes. @@ -102,6 +103,7 @@ def deprecated_decorator(func: Callable[P, T]) -> Callable[P, T]: remove_in=remove_in, prefix=f"{func.__module__}.{func.__qualname__}", addendum=addendum, + deprecation_type=deprecation_type, ) # alert developer that it's time to remove something @@ -128,6 +130,7 @@ def argument( rename: str | None = None, addendum: str | None = None, stack: int = 0, + deprecation_type: type[Warning] = DeprecationWarning, ) -> Callable[[Callable[P, T]], Callable[P, T]]: """Deprecation decorator for keyword arguments. @@ -149,6 +152,7 @@ def deprecated_decorator(func: Callable[P, T]) -> Callable[P, T]: addendum=( f"Use '{rename}' instead." if rename and not addendum else addendum ), + deprecation_type=deprecation_type, ) # alert developer that it's time to remove something @@ -181,6 +185,7 @@ def action( *, addendum: str | None = None, stack: int = 0, + deprecation_type: type[Warning] = FutureWarning, ) -> ActionType: """Wraps any argparse.Action to issue a deprecation warning.""" @@ -203,7 +208,7 @@ def __init__(inner_self: Self, *args: Any, **kwargs: Any) -> None: else f"`{inner_self.dest}`" ), addendum=addendum, - deprecation_type=FutureWarning, + deprecation_type=deprecation_type, ) # alert developer that it's time to remove something @@ -263,6 +268,7 @@ def constant( *, addendum: str | None = None, stack: int = 0, + deprecation_type: type[Warning] = DeprecationWarning, ) -> None: """Deprecation function for module constant/global. @@ -281,6 +287,7 @@ def constant( remove_in=remove_in, prefix=f"{fullname}.{constant}", addendum=addendum, + deprecation_type=deprecation_type, ) # alert developer that it's time to remove something @@ -310,6 +317,7 @@ def topic( topic: str, addendum: str | None = None, stack: int = 0, + deprecation_type: type[Warning] = DeprecationWarning, ) -> None: """Deprecation function for a topic. @@ -325,6 +333,7 @@ def topic( remove_in=remove_in, prefix=topic, addendum=addendum, + deprecation_type=deprecation_type, ) # alert developer that it's time to remove something @@ -379,7 +388,7 @@ def _generate_message( prefix: str, addendum: str | None, *, - deprecation_type: type[Warning] = DeprecationWarning, + deprecation_type: type[Warning], ) -> tuple[type[Warning] | None, str]: """Generate the standardized deprecation message and determine whether the deprecation is pending, active, or past. diff --git a/news/3192-deprecate-testing-recipes b/news/3192-deprecate-testing-recipes new file mode 100644 index 0000000000..cbe29eb663 --- /dev/null +++ b/news/3192-deprecate-testing-recipes @@ -0,0 +1,19 @@ +### Enhancements + +* + +### Bug fixes + +* + +### Deprecations + +* Mark `conda_build.build._construct_metadata_for_test_from_recipe` as deprecated. Test built packages instead, not recipes (e.g., `conda build --test package` instead of `conda build --test recipe/`). (#3192) + +### Docs + +* + +### Other + +* diff --git a/tests/test_build.py b/tests/test_build.py index 49fc1a4924..dcfeeeeab6 100644 --- a/tests/test_build.py +++ b/tests/test_build.py @@ -12,12 +12,16 @@ import sys from contextlib import nullcontext from pathlib import Path +from typing import TYPE_CHECKING import pytest from conda_build import api, build -from .utils import get_noarch_python_meta, metadata_dir +from .utils import get_noarch_python_meta, metadata_dir, metadata_path + +if TYPE_CHECKING: + from conda_build.config import Config def test_build_preserves_PATH(testing_config): @@ -329,3 +333,11 @@ def test_guess_interpreter( def test_check_external(): with pytest.deprecated_call(): build.check_external() + + +def test_construct_metadata_for_test_from_recipe(testing_config: Config) -> None: + with pytest.warns(FutureWarning): + build._construct_metadata_for_test_from_recipe( + str(metadata_path / "test_source_files"), + testing_config, + )