Skip to content

Commit

Permalink
Tests: Fix get_or_merge_testing_config for cli tests (#5076)
Browse files Browse the repository at this point in the history
* Tests: Fix get_or_merge_testing_config cli tests

cli.main_build.execute (et al.) call the function with **args.__dict__
with args having default values (e.g., croot=None) via parse_args.

Signed-off-by: Marcel Bargull <marcel.bargull@udo.edu>

* Fix some concurrency issues in tests

Signed-off-by: Marcel Bargull <marcel.bargull@udo.edu>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Add comment for test concurrency issue workaround

Signed-off-by: Marcel Bargull <marcel.bargull@udo.edu>

---------

Signed-off-by: Marcel Bargull <marcel.bargull@udo.edu>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
mbargull and pre-commit-ci[bot] authored Nov 20, 2023
1 parent 67cc72e commit bc46f28
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
6 changes: 2 additions & 4 deletions tests/cli/test_main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# SPDX-License-Identifier: BSD-3-Clause
import os
import re
import sys
from pathlib import Path

import pytest
Expand Down Expand Up @@ -104,8 +103,7 @@ def test_build_output_build_path(
args = ["--output", testing_workdir]
main_build.execute(args)
test_path = os.path.join(
sys.prefix,
"conda-bld",
testing_config.croot,
testing_config.host_subdir,
"test_build_output_build_path-1.0-1.tar.bz2",
)
Expand All @@ -125,7 +123,7 @@ def test_build_output_build_path_multiple_recipes(
main_build.execute(args)

test_path = lambda pkg: os.path.join(
sys.prefix, "conda-bld", testing_config.host_subdir, pkg
testing_config.croot, testing_config.host_subdir, pkg
)
test_paths = [
test_path("test_build_output_build_path_multiple_recipes-1.0-1.tar.bz2"),
Expand Down
14 changes: 10 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,17 @@ def default_testing_config(testing_config, monkeypatch, request):
return

def get_or_merge_testing_config(config, variant=None, **kwargs):
merged_kwargs = {}
if not config:
merged_kwargs.update(testing_config._testing_config_kwargs)
merged_kwargs.update(kwargs)
return _get_or_merge_config(config, variant, **merged_kwargs)
# If no existing config, override kwargs that are None with testing config defaults.
# (E.g., "croot" is None if called via "(..., *args.__dict__)" in cli.main_build.)
kwargs.update(
{
key: value
for key, value in testing_config._testing_config_kwargs.items()
if kwargs.get(key) is None
}
)
return _get_or_merge_config(config, variant, **kwargs)

monkeypatch.setattr(
conda_build.config,
Expand Down
4 changes: 4 additions & 0 deletions tests/test-recipes/metadata/entry_points/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ requirements:
- setuptools
run:
- python

# Ensure we get different build strings for concurrently tested packages.
extra:
dummy: '{{ pytest_name is defined }}'
25 changes: 14 additions & 11 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1655,14 +1655,17 @@ def test_provides_features_metadata(testing_config):
assert index["provides_features"] == {"test2": "also_ok"}


# using different MACOSX_DEPLOYMENT_TARGET in parallel causes some SDK race condition
# https://github.com/conda/conda-build/issues/4708
@pytest.mark.serial
def test_overlinking_detection(testing_config, variants_conda_build_sysroot):
def test_overlinking_detection(
testing_config, testing_workdir, variants_conda_build_sysroot
):
testing_config.activate = True
testing_config.error_overlinking = True
testing_config.verify = False
recipe = os.path.join(metadata_dir, "_overlinking_detection")
recipe = os.path.join(testing_workdir, "recipe")
copy_into(
os.path.join(metadata_dir, "_overlinking_detection"),
recipe,
)
dest_sh = os.path.join(recipe, "build.sh")
dest_bat = os.path.join(recipe, "bld.bat")
copy_into(
Expand All @@ -1684,17 +1687,17 @@ def test_overlinking_detection(testing_config, variants_conda_build_sysroot):
rm_rf(dest_bat)


# using different MACOSX_DEPLOYMENT_TARGET in parallel causes some SDK race condition
# https://github.com/conda/conda-build/issues/4708
@pytest.mark.serial
@pytest.mark.flaky(reruns=5, reruns_delay=2)
def test_overlinking_detection_ignore_patterns(
testing_config, variants_conda_build_sysroot
testing_config, testing_workdir, variants_conda_build_sysroot
):
testing_config.activate = True
testing_config.error_overlinking = True
testing_config.verify = False
recipe = os.path.join(metadata_dir, "_overlinking_detection_ignore_patterns")
recipe = os.path.join(testing_workdir, "recipe")
copy_into(
os.path.join(metadata_dir, "_overlinking_detection_ignore_patterns"),
recipe,
)
dest_sh = os.path.join(recipe, "build.sh")
dest_bat = os.path.join(recipe, "bld.bat")
copy_into(
Expand Down
13 changes: 10 additions & 3 deletions tests/test_api_build_conda_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@


@pytest.mark.parametrize("pkg_format,pkg_ext", [(None, ".tar.bz2"), ("2", ".conda")])
def test_conda_pkg_format(pkg_format, pkg_ext, testing_config, monkeypatch, capfd):
def test_conda_pkg_format(
pkg_format, pkg_ext, testing_config, monkeypatch, capfd, request
):
"""Conda package format "2" builds .conda packages."""

# Build the "entry_points" recipe, which contains a test pass for package.
Expand All @@ -23,10 +25,15 @@ def test_conda_pkg_format(pkg_format, pkg_ext, testing_config, monkeypatch, capf
monkeypatch.setenv("CONDA_TEST_VAR", "conda_test")
monkeypatch.setenv("CONDA_TEST_VAR_2", "conda_test_2")

(output_file,) = api.get_output_file_paths(recipe, config=testing_config)
# Recipe "entry_points" is used in other test -> add test-specific variant
# (change build hash) to avoid clashes in package cache from other tests.
variants = {"pytest_name": [request.node.name]}
(output_file,) = api.get_output_file_paths(
recipe, config=testing_config, variants=variants
)
assert output_file.endswith(pkg_ext)

api.build(recipe, config=testing_config)
api.build(recipe, config=testing_config, variants=variants)
assert os.path.exists(output_file)

out, err = capfd.readouterr()
Expand Down
7 changes: 5 additions & 2 deletions tests/test_api_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,12 @@ def test_convert_platform_to_others(base_platform, package):
@pytest.mark.skipif(
on_win, reason="we create the pkg to be converted in *nix; don't run on win."
)
def test_convert_from_unix_to_win_creates_entry_points(testing_config):
def test_convert_from_unix_to_win_creates_entry_points(testing_config, request):
recipe_dir = os.path.join(metadata_dir, "entry_points")
fn = api.build(recipe_dir, config=testing_config)[0]
# Recipe "entry_points" is used in other test -> add test-specific variant
# (change build hash) to avoid clashes in package cache from other tests.
variants = {"pytest_name": [request.node.name]}
fn = api.build(recipe_dir, config=testing_config, variants=variants)[0]
for platform in ["win-64", "win-32"]:
api.convert(fn, platforms=[platform], force=True)
converted_fn = os.path.join(platform, os.path.basename(fn))
Expand Down

0 comments on commit bc46f28

Please sign in to comment.