From 47c511fdacc2eb94d9286300e789825482b0fcc2 Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 29 Oct 2024 11:34:29 +0100 Subject: [PATCH] Fix tests --- tests/test_packagelist.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_packagelist.py b/tests/test_packagelist.py index d46346bf..7ca6aa47 100644 --- a/tests/test_packagelist.py +++ b/tests/test_packagelist.py @@ -157,10 +157,14 @@ def test_replacement_recipe_given(self): @mock.patch("alibuild_helpers.utilities.dieOnError") def test_missing_replacement_spec(self, mock_dieOnError): """Check an error is thrown when the replacement spec is not found.""" - specs, systemPkgs, ownPkgs, failedReqs, validDefaults = \ - getPackageListWithDefaults(["missing-spec"]) - mock_dieOnError.assert_any_call(True, "Could not find named replacement " - "spec for missing-spec: missing_tag") + assert_msg = "Could not find named replacement spec for missing-spec: missing_tag" + # Change the behaviour from sys.exit to a regular exception. Without it + # we don't stop execution properly and other asserts might trigger + mock_dieOnError.side_effect = lambda cond, _: (_ for _ in ()).throw(Exception("dieOnError called")) if cond else None + with self.assertRaises(Exception, msg=assert_msg) as context: + specs, systemPkgs, ownPkgs, failedReqs, validDefaults = \ + getPackageListWithDefaults(["missing-spec"]) + self.assertEqual(str(context.exception), "dieOnError called", msg=assert_msg) @mock.patch("alibuild_helpers.utilities.getRecipeReader", new=MockReader)