Skip to content

Commit

Permalink
Replace sys.exit call in conda_build.build.tests_failed (#5370)
Browse files Browse the repository at this point in the history
  • Loading branch information
beeankha committed Jun 18, 2024
1 parent 7d74dd6 commit 4457362
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 10 deletions.
9 changes: 7 additions & 2 deletions conda_build/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -3553,7 +3553,12 @@ def test(
return True


def tests_failed(package_or_metadata, move_broken, broken_dir, config):
def tests_failed(
package_or_metadata: str | os.PathLike | Path | MetaData,
move_broken: bool,
broken_dir: str | os.PathLike | Path,
config: Config,
) -> None:
"""
Causes conda to exit if any of the given package's tests failed.
Expand Down Expand Up @@ -3581,7 +3586,7 @@ def tests_failed(package_or_metadata, move_broken, broken_dir, config):
_delegated_update_index(
os.path.dirname(os.path.dirname(pkg)), verbose=config.debug, threads=1
)
sys.exit("TESTS FAILED: " + os.path.basename(pkg))
raise CondaBuildUserError("TESTS FAILED: " + os.path.basename(pkg))


@deprecated(
Expand Down
6 changes: 3 additions & 3 deletions tests/cli/test_main_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Config,
zstd_compression_level_default,
)
from conda_build.exceptions import DependencyNeedsBuildingError
from conda_build.exceptions import CondaBuildUserError, DependencyNeedsBuildingError
from conda_build.os_utils.external import find_executable
from conda_build.utils import get_build_folders, on_win, package_has_file

Expand Down Expand Up @@ -165,7 +165,7 @@ def test_build_long_test_prefix_default_enabled(mocker, testing_workdir):
main_build.execute(args)

args.append("--no-long-test-prefix")
with pytest.raises(SystemExit):
with pytest.raises(CondaBuildUserError):
main_build.execute(args)


Expand Down Expand Up @@ -483,7 +483,7 @@ def test_test_extra_dep(testing_metadata):
main_build.execute(args)

# missing click dep will fail tests
with pytest.raises(SystemExit):
with pytest.raises(CondaBuildUserError):
args = [output, "-t"]
# extra_deps will add it in
main_build.execute(args)
Expand Down
7 changes: 4 additions & 3 deletions tests/test_api_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from conda_build.exceptions import (
BuildScriptException,
CondaBuildException,
CondaBuildUserError,
DependencyNeedsBuildingError,
OverDependingError,
OverLinkingError,
Expand Down Expand Up @@ -279,7 +280,7 @@ def test_no_include_recipe_meta_yaml(testing_metadata, testing_config):
)[0]
assert not package_has_file(output_file, "info/recipe/meta.yaml")

with pytest.raises(SystemExit):
with pytest.raises(CondaBuildUserError):
# we are testing that even with the recipe excluded, we still get the tests in place
output_file = api.build(
os.path.join(metadata_dir, "_no_include_recipe"), config=testing_config
Expand Down Expand Up @@ -545,7 +546,7 @@ def test_skip_existing_url(testing_metadata, testing_workdir, capfd):

def test_failed_tests_exit_build(testing_config):
"""https://github.com/conda/conda-build/issues/1112"""
with pytest.raises(SystemExit, match="TESTS FAILED"):
with pytest.raises(CondaBuildUserError, match="TESTS FAILED"):
api.build(
os.path.join(metadata_dir, "_test_failed_test_exits"), config=testing_config
)
Expand Down Expand Up @@ -1808,7 +1809,7 @@ def test_downstream_tests(testing_config):
upstream = os.path.join(metadata_dir, "_test_downstreams/upstream")
downstream = os.path.join(metadata_dir, "_test_downstreams/downstream")
api.build(downstream, config=testing_config, notest=True)
with pytest.raises(SystemExit):
with pytest.raises(CondaBuildUserError):
api.build(upstream, config=testing_config)


Expand Down
3 changes: 2 additions & 1 deletion tests/test_api_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest

from conda_build import api
from conda_build.exceptions import CondaBuildUserError

from .utils import metadata_dir

Expand Down Expand Up @@ -63,5 +64,5 @@ def test_api_extra_dep(testing_metadata):
api.test(output, config=testing_metadata.config, extra_deps=["click"])

# missing click dep will fail tests
with pytest.raises(SystemExit):
with pytest.raises(CondaBuildUserError):
api.test(output, config=testing_metadata.config)
10 changes: 10 additions & 0 deletions tests/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,3 +381,13 @@ def test_handle_anaconda_upload(testing_config: Config, mocker: MockerFixture):

with pytest.raises(CondaBuildUserError):
build.handle_anaconda_upload((), testing_config)


def test_tests_failed(testing_metadata: MetaData, tmp_path: Path):
with pytest.raises(CondaBuildUserError):
build.tests_failed(
package_or_metadata=testing_metadata,
move_broken=True,
broken_dir=tmp_path,
config=testing_metadata.config,
)
3 changes: 2 additions & 1 deletion tests/test_subpackages.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from conda.base.context import context

from conda_build import api, utils
from conda_build.exceptions import CondaBuildUserError
from conda_build.metadata import MetaDataTuple
from conda_build.render import finalize_metadata

Expand Down Expand Up @@ -292,7 +293,7 @@ def test_per_output_tests(testing_config):
@pytest.mark.sanity
def test_per_output_tests_script(testing_config):
recipe_dir = os.path.join(subpackage_dir, "_output_test_script")
with pytest.raises(SystemExit):
with pytest.raises(CondaBuildUserError):
api.build(recipe_dir, config=testing_config)


Expand Down

0 comments on commit 4457362

Please sign in to comment.