@@ -303,9 +303,8 @@ def test_bump_tag_exists_raises_exception(util: UtilFixture):
303303 util .create_file_and_commit ("feat: new file" )
304304 git .tag ("0.2.0" )
305305
306- with pytest .raises (BumpTagFailedError ) as excinfo :
306+ with pytest .raises (BumpTagFailedError , match = re . escape ( "0.2.0" )) :
307307 util .run_cli ("bump" , "--yes" )
308- assert "0.2.0" in str (excinfo .value ) # This should be a fatal error
309308
310309
311310@pytest .mark .usefixtures ("tmp_commitizen_project" )
@@ -327,18 +326,17 @@ def test_bump_when_bumping_is_not_support(util: UtilFixture):
327326 "feat: new user interface\n \n BREAKING CHANGE: age is no longer supported"
328327 )
329328
330- with pytest .raises (NoPatternMapError ) as excinfo :
329+ with pytest .raises (NoPatternMapError , match = "'cz_jira' rule does not support bump" ) :
331330 util .run_cli ("-n" , "cz_jira" , "bump" , "--yes" )
332- assert "'cz_jira' rule does not support bump" in str (excinfo .value )
333331
334332
335333@pytest .mark .usefixtures ("tmp_git_project" )
336334def test_bump_when_version_is_not_specify (util : UtilFixture ):
337- with pytest .raises (NoVersionSpecifiedError ) as excinfo :
335+ with pytest .raises (
336+ NoVersionSpecifiedError , match = re .escape (NoVersionSpecifiedError .message )
337+ ):
338338 util .run_cli ("bump" )
339339
340- assert NoVersionSpecifiedError .message in str (excinfo .value )
341-
342340
343341@pytest .mark .usefixtures ("tmp_commitizen_project" )
344342def test_bump_when_no_new_commit (util : UtilFixture ):
@@ -349,11 +347,11 @@ def test_bump_when_no_new_commit(util: UtilFixture):
349347 util .run_cli ("bump" , "--yes" )
350348
351349 # bump without a new commit.
352- with pytest .raises (NoCommitsFoundError ) as excinfo :
350+ with pytest .raises (
351+ NoCommitsFoundError , match = r"\[NO_COMMITS_FOUND\]\nNo new commits found\."
352+ ):
353353 util .run_cli ("bump" , "--yes" )
354354
355- assert "[NO_COMMITS_FOUND]\n No new commits found." in str (excinfo .value )
356-
357355
358356def test_bump_when_version_inconsistent_in_version_files (
359357 tmp_commitizen_project , util : UtilFixture
@@ -369,11 +367,11 @@ def test_bump_when_version_inconsistent_in_version_files(
369367
370368 util .create_file_and_commit ("feat: new file" )
371369
372- with pytest .raises (CurrentVersionNotFoundError ) as excinfo :
370+ with pytest .raises (
371+ CurrentVersionNotFoundError , match = "Current version 0.1.0 is not found in"
372+ ):
373373 util .run_cli ("bump" , "--yes" , "--check-consistency" )
374374
375- assert "Current version 0.1.0 is not found in" in str (excinfo .value )
376-
377375
378376def test_bump_major_version_zero_when_major_is_not_zero (
379377 tmp_commitizen_project , util : UtilFixture
@@ -394,13 +392,12 @@ def test_bump_major_version_zero_when_major_is_not_zero(
394392 util .create_tag ("v1.0.0" )
395393 util .create_file_and_commit ("feat(user)!: new file" )
396394
397- with pytest .raises (NotAllowed ) as excinfo :
395+ with pytest .raises (
396+ NotAllowed ,
397+ match = "--major-version-zero is meaningless for current version 1.0.0" ,
398+ ):
398399 util .run_cli ("bump" , "--yes" , "--major-version-zero" )
399400
400- assert "--major-version-zero is meaningless for current version 1.0.0" in str (
401- excinfo .value
402- )
403-
404401
405402def test_bump_files_only (tmp_commitizen_project , util : UtilFixture ):
406403 tmp_version_file = tmp_commitizen_project .join ("__version__.py" )
@@ -538,13 +535,14 @@ def test_prevent_prerelease_when_no_increment_detected(
538535
539536 util .create_file_and_commit ("test: new file" )
540537
541- with pytest .raises (NoCommitsFoundError ) as excinfo :
538+ with pytest .raises (
539+ NoCommitsFoundError ,
540+ match = re .escape (
541+ "[NO_COMMITS_FOUND]\n No commits found to generate a pre-release."
542+ ),
543+ ):
542544 util .run_cli ("bump" , "-pr" , "beta" )
543545
544- assert "[NO_COMMITS_FOUND]\n No commits found to generate a pre-release." in str (
545- excinfo .value
546- )
547-
548546
549547@pytest .mark .usefixtures ("tmp_commitizen_project" )
550548def test_bump_with_changelog_to_stdout_arg (
@@ -735,14 +733,14 @@ def test_bump_invalid_manual_version_raises_exception(
735733):
736734 util .create_file_and_commit ("feat: new file" )
737735
738- with pytest .raises (InvalidManualVersion ) as excinfo :
736+ with pytest .raises (
737+ InvalidManualVersion ,
738+ match = re .escape (
739+ f"[INVALID_MANUAL_VERSION]\n Invalid manual version: '{ manual_version } '"
740+ ),
741+ ):
739742 util .run_cli ("bump" , "--yes" , manual_version )
740743
741- assert (
742- f"[INVALID_MANUAL_VERSION]\n Invalid manual version: '{ manual_version } '"
743- in str (excinfo .value )
744- )
745-
746744
747745@pytest .mark .usefixtures ("tmp_commitizen_project" )
748746@pytest .mark .parametrize (
@@ -770,13 +768,12 @@ def test_bump_manual_version(util: UtilFixture, manual_version):
770768@pytest .mark .usefixtures ("tmp_commitizen_project" )
771769def test_bump_manual_version_disallows_major_version_zero (util : UtilFixture ):
772770 util .create_file_and_commit ("feat: new file" )
773- with pytest .raises (NotAllowed ) as excinfo :
771+ with pytest .raises (
772+ NotAllowed ,
773+ match = "--major-version-zero cannot be combined with MANUAL_VERSION" ,
774+ ):
774775 util .run_cli ("bump" , "--yes" , "--major-version-zero" , "0.2.0" )
775776
776- assert "--major-version-zero cannot be combined with MANUAL_VERSION" in str (
777- excinfo .value
778- )
779-
780777
781778@pytest .mark .parametrize (
782779 "initial_version, expected_version_after_bump" ,
0 commit comments