From efe302f4dd64840dace3de9750541fdab787adfa Mon Sep 17 00:00:00 2001 From: Marcel Bargull Date: Tue, 29 Nov 2022 11:17:08 +0100 Subject: [PATCH] test: monkeypatch get_or_merge_config instead api --- tests/conftest.py | 53 +++++++---------------------- tests/test_api_build.py | 2 -- tests/test_api_build_conda_v2.py | 2 -- tests/test_api_build_dll_package.py | 2 -- tests/test_api_build_go_package.py | 2 -- tests/test_api_consistency.py | 2 ++ tests/test_api_convert.py | 2 -- tests/test_api_debug.py | 2 -- tests/test_api_render.py | 2 -- tests/test_api_skeleton.py | 2 -- tests/test_api_skeleton_cran.py | 2 -- tests/test_api_test.py | 2 -- tests/test_metadata.py | 2 -- tests/test_post.py | 2 -- tests/test_published_examples.py | 2 -- tests/test_subpackages.py | 2 -- tests/test_variants.py | 2 -- 17 files changed, 15 insertions(+), 70 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index d319a3399c..152205b95b 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,15 +1,15 @@ # Copyright (C) 2014 Anaconda, Inc # SPDX-License-Identifier: BSD-3-Clause -import inspect import os import sys from collections import defaultdict import pytest -import conda_build.api +import conda_build.config from conda_build.config import ( Config, + get_or_merge_config, _src_cache_root_default, conda_pkg_format_default, enable_static_default, @@ -123,52 +123,25 @@ def boolify(v): return result -@pytest.fixture(scope="function") -def api_default_testing_config(testing_config, request): - """Monkeypatch conda_build.api functions to use config=testing_config default +@pytest.fixture(scope="function", autouse=True) +def default_testing_config(testing_config, monkeypatch, request): + """Monkeypatch get_or_merge_config to use testing_config by default This requests fixture testing_config, thus implicitly testing_workdir, too. """ # Allow single tests to disable this fixture even if outer scope adds it. - if "no_api_default_testing_config" in request.keywords: + if "no_default_testing_config" in request.keywords: return - arg_name = "config" - new_default = testing_config - - saved_defaults = {} - saved_kwdefaults = {} + def get_or_merge_testing_config(config, variant=None, **kwargs): + return get_or_merge_config(config or testing_config, variant, **kwargs) - module = conda_build.api - for _, member in inspect.getmembers(module, inspect.isfunction): - if inspect.getmodule(member) is not module: - continue - arg_spec = inspect.getfullargspec(member) - defaults = member.__defaults__ - kwdefaults = member.__kwdefaults__ - try: - index = arg_spec.args[-len(defaults):].index(arg_name) - except (TypeError, ValueError): - pass - else: - saved_defaults[member] = defaults - member.__defaults__ = defaults[:index] + (new_default,) + defaults[index + 1:] - try: - kwdefaults[arg_name] - except (TypeError, KeyError): - pass - else: - saved_kwdefaults[member] = kwdefaults - member.__kwdefaults__ = {**kwdefaults, arg_name: new_default} - - def restore_defaults(): - for func, defaults in saved_defaults.items(): - func.__defaults__ = defaults - for func, kwdefaults in saved_kwdefaults.items(): - func.__kwdefaults__ = kwdefaults - - request.addfinalizer(restore_defaults) + monkeypatch.setatr( + conda_build.config, + "get_or_merge_config", + get_or_merge_testing_config, + ) @pytest.fixture(scope="function") diff --git a/tests/test_api_build.py b/tests/test_api_build.py index 84ab0b0d1f..bf1dc00af9 100644 --- a/tests/test_api_build.py +++ b/tests/test_api_build.py @@ -46,8 +46,6 @@ from .utils import is_valid_dir, metadata_dir, fail_dir, add_mangling -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - # define a few commonly used recipes - use os.path.join(metadata_dir, recipe) elsewhere empty_sections = os.path.join(metadata_dir, "empty_sections") diff --git a/tests/test_api_build_conda_v2.py b/tests/test_api_build_conda_v2.py index 82c8822b0e..b7c38a96e8 100644 --- a/tests/test_api_build_conda_v2.py +++ b/tests/test_api_build_conda_v2.py @@ -8,8 +8,6 @@ from .utils import metadata_dir -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - @pytest.mark.parametrize("pkg_format,pkg_ext", [(None, ".tar.bz2"), ("2", ".conda")]) def test_conda_pkg_format( diff --git a/tests/test_api_build_dll_package.py b/tests/test_api_build_dll_package.py index 0d48dd1313..32adb88cc4 100644 --- a/tests/test_api_build_dll_package.py +++ b/tests/test_api_build_dll_package.py @@ -7,8 +7,6 @@ from .utils import thisdir -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - @pytest.fixture() def recipe(): diff --git a/tests/test_api_build_go_package.py b/tests/test_api_build_go_package.py index 6752a886d5..16e7a27385 100644 --- a/tests/test_api_build_go_package.py +++ b/tests/test_api_build_go_package.py @@ -7,8 +7,6 @@ from .utils import thisdir -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - @pytest.fixture() def recipe(): diff --git a/tests/test_api_consistency.py b/tests/test_api_consistency.py index a3cce8cfa2..36dfa847bd 100644 --- a/tests/test_api_consistency.py +++ b/tests/test_api_consistency.py @@ -9,6 +9,8 @@ from inspect import getfullargspec as getargspec +pytestmark = pytest.mark.no_default_testing_config + def test_api_config(): assert hasattr(api, 'Config') diff --git a/tests/test_api_convert.py b/tests/test_api_convert.py index a1b72c9238..dc973467da 100644 --- a/tests/test_api_convert.py +++ b/tests/test_api_convert.py @@ -14,8 +14,6 @@ from .utils import metadata_dir, assert_package_consistency -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - def test_convert_wheel_raises(): with pytest.raises(RuntimeError) as exc: diff --git a/tests/test_api_debug.py b/tests/test_api_debug.py index 90aa8d5d5f..10415c15d1 100644 --- a/tests/test_api_debug.py +++ b/tests/test_api_debug.py @@ -18,8 +18,6 @@ from .utils import metadata_dir, thisdir, on_win -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - recipe_path = os.path.join(metadata_dir, "_debug_pkg") ambiguous_recipe_path = os.path.join(metadata_dir, "_debug_pkg_multiple_outputs") tarball_path = os.path.join(thisdir, "archives", "test_debug_pkg-1.0-0.tar.bz2") diff --git a/tests/test_api_render.py b/tests/test_api_render.py index 76bdb9d9fc..452a642e43 100644 --- a/tests/test_api_render.py +++ b/tests/test_api_render.py @@ -19,8 +19,6 @@ from .utils import metadata_dir, thisdir -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - def test_render_need_download(testing_workdir, testing_config): # first, test that the download/render system renders all it can, diff --git a/tests/test_api_skeleton.py b/tests/test_api_skeleton.py index 53eeaf2a88..2c1a3b0001 100644 --- a/tests/test_api_skeleton.py +++ b/tests/test_api_skeleton.py @@ -27,8 +27,6 @@ import conda_build.os_utils.external as external from conda_build.utils import on_win -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - thisdir = os.path.dirname(os.path.realpath(__file__)) repo_packages = [('', 'pypi', 'pip', '8.1.2'), diff --git a/tests/test_api_skeleton_cran.py b/tests/test_api_skeleton_cran.py index 127dc96ab7..52babe2098 100644 --- a/tests/test_api_skeleton_cran.py +++ b/tests/test_api_skeleton_cran.py @@ -13,8 +13,6 @@ from conda_build.skeletons.cran import CRAN_BUILD_SH_SOURCE, CRAN_META from conda_build.utils import ensure_list -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - # CRAN packages to test license_file entry. # (package, license_id, license_family, license_files) diff --git a/tests/test_api_test.py b/tests/test_api_test.py index f2df3af518..4bb70a220c 100644 --- a/tests/test_api_test.py +++ b/tests/test_api_test.py @@ -11,8 +11,6 @@ from conda_build import api from .utils import metadata_dir -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - @pytest.mark.sanity def test_recipe_test(testing_workdir, testing_config): diff --git a/tests/test_metadata.py b/tests/test_metadata.py index ccbdde23b3..2bf9b0c045 100644 --- a/tests/test_metadata.py +++ b/tests/test_metadata.py @@ -12,8 +12,6 @@ from conda_build.utils import DEFAULT_SUBDIRS from conda_build.metadata import _hash_dependencies -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - def test_uses_vcs_in_metadata(testing_workdir, testing_metadata): testing_metadata._meta_path = os.path.join(testing_workdir, 'meta.yaml') diff --git a/tests/test_post.py b/tests/test_post.py index 0394e3feb9..a008c6656a 100644 --- a/tests/test_post.py +++ b/tests/test_post.py @@ -11,8 +11,6 @@ from .utils import add_mangling, metadata_dir -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - def test_compile_missing_pyc(testing_workdir): good_files = ['f1.py', 'f3.py'] diff --git a/tests/test_published_examples.py b/tests/test_published_examples.py index 8fc79f2dd1..2d76a08e6c 100644 --- a/tests/test_published_examples.py +++ b/tests/test_published_examples.py @@ -10,8 +10,6 @@ from conda_build.utils import check_call_env from .utils import metadata_dir, is_valid_dir -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - published_examples = os.path.join(os.path.dirname(metadata_dir), 'published_code') diff --git a/tests/test_subpackages.py b/tests/test_subpackages.py index 6c2b9ecf22..e2b0b59855 100644 --- a/tests/test_subpackages.py +++ b/tests/test_subpackages.py @@ -13,8 +13,6 @@ from .utils import subpackage_dir, is_valid_dir -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - @pytest.fixture(params=[dirname for dirname in os.listdir(subpackage_dir) if is_valid_dir(subpackage_dir, dirname)]) diff --git a/tests/test_variants.py b/tests/test_variants.py index 987eae7368..e8ace350a7 100644 --- a/tests/test_variants.py +++ b/tests/test_variants.py @@ -12,8 +12,6 @@ from conda_build import api, exceptions, variants from conda_build.utils import package_has_file -pytestmark = pytest.mark.usefixtures("api_default_testing_config") - thisdir = os.path.dirname(__file__) recipe_dir = os.path.join(thisdir, 'test-recipes', 'variants')