@@ -149,18 +149,12 @@ def test_check_conventional_commit_succeeds(
149149 ),
150150 ),
151151)
152- def test_check_no_conventional_commit (commit_msg , config , mocker : MockFixture , tmpdir ):
153- with pytest .raises (InvalidCommitMessageError ):
154- error_mock = mocker .patch ("commitizen.out.error" )
155-
156- tempfile = tmpdir .join ("temp_commit_file" )
157- tempfile .write (commit_msg )
152+ def test_check_no_conventional_commit (commit_msg , config , tmpdir ):
153+ tempfile = tmpdir .join ("temp_commit_file" )
154+ tempfile .write (commit_msg )
158155
159- check_cmd = commands .Check (
160- config = config , arguments = {"commit_msg_file" : tempfile }
161- )
162- check_cmd ()
163- error_mock .assert_called_once ()
156+ with pytest .raises (InvalidCommitMessageError ):
157+ commands .Check (config = config , arguments = {"commit_msg_file" : tempfile })()
164158
165159
166160@pytest .mark .parametrize (
@@ -204,18 +198,14 @@ def test_check_a_range_of_git_commits(config, mocker: MockFixture):
204198
205199
206200def test_check_a_range_of_git_commits_and_failed (config , mocker : MockFixture ):
207- error_mock = mocker .patch ("commitizen.out.error" )
208201 mocker .patch (
209202 "commitizen.git.get_commits" ,
210203 return_value = _build_fake_git_commits (["This commit does not follow rule" ]),
211204 )
212- check_cmd = commands .Check (
213- config = config , arguments = {"rev_range" : "HEAD~10..master" }
214- )
215205
216- with pytest .raises (InvalidCommitMessageError ):
217- check_cmd ()
218- error_mock . assert_called_once ( )
206+ with pytest .raises (InvalidCommitMessageError ) as excinfo :
207+ commands . Check ( config = config , arguments = { "rev_range" : "HEAD~10..master" }) ()
208+ assert "This commit does not follow rule" in str ( excinfo . value )
219209
220210
221211def test_check_command_with_invalid_argument (config ):
@@ -271,86 +261,54 @@ def test_check_command_with_valid_message(config, mocker: MockFixture):
271261 success_mock .assert_called_once ()
272262
273263
274- def test_check_command_with_invalid_message (config , mocker : MockFixture ):
275- error_mock = mocker .patch ("commitizen.out.error" )
276- check_cmd = commands .Check (config = config , arguments = {"message" : "bad commit" })
277-
278- with pytest .raises (InvalidCommitMessageError ):
279- check_cmd ()
280- error_mock .assert_called_once ()
281-
282-
283- def test_check_command_with_empty_message (config , mocker : MockFixture ):
284- error_mock = mocker .patch ("commitizen.out.error" )
285- check_cmd = commands .Check (config = config , arguments = {"message" : "" })
286-
264+ @pytest .mark .parametrize ("message" , ["bad commit" , "" ])
265+ def test_check_command_with_invalid_message (config , message ):
287266 with pytest .raises (InvalidCommitMessageError ):
288- check_cmd ()
289- error_mock .assert_called_once ()
267+ commands .Check (config = config , arguments = {"message" : message })()
290268
291269
292270def test_check_command_with_allow_abort_arg (config , mocker : MockFixture ):
293271 success_mock = mocker .patch ("commitizen.out.success" )
294- check_cmd = commands .Check (
295- config = config , arguments = {"message" : "" , "allow_abort" : True }
296- )
297-
298- check_cmd ()
272+ commands .Check (config = config , arguments = {"message" : "" , "allow_abort" : True })()
299273 success_mock .assert_called_once ()
300274
301275
302276def test_check_command_with_allow_abort_config (config , mocker : MockFixture ):
303277 success_mock = mocker .patch ("commitizen.out.success" )
304278 config .settings ["allow_abort" ] = True
305- check_cmd = commands .Check (config = config , arguments = {"message" : "" })
306-
307- check_cmd ()
279+ commands .Check (config = config , arguments = {"message" : "" })()
308280 success_mock .assert_called_once ()
309281
310282
311- def test_check_command_override_allow_abort_config (config , mocker : MockFixture ):
312- error_mock = mocker .patch ("commitizen.out.error" )
283+ def test_check_command_override_allow_abort_config (config ):
313284 config .settings ["allow_abort" ] = True
314- check_cmd = commands .Check (
315- config = config , arguments = {"message" : "" , "allow_abort" : False }
316- )
317-
318285 with pytest .raises (InvalidCommitMessageError ):
319- check_cmd ()
320- error_mock .assert_called_once ()
286+ commands .Check (config = config , arguments = {"message" : "" , "allow_abort" : False })()
321287
322288
323289def test_check_command_with_allowed_prefixes_arg (config , mocker : MockFixture ):
324290 success_mock = mocker .patch ("commitizen.out.success" )
325- check_cmd = commands .Check (
291+ commands .Check (
326292 config = config ,
327293 arguments = {"message" : "custom! test" , "allowed_prefixes" : ["custom!" ]},
328- )
329-
330- check_cmd ()
294+ )()
331295 success_mock .assert_called_once ()
332296
333297
334298def test_check_command_with_allowed_prefixes_config (config , mocker : MockFixture ):
335299 success_mock = mocker .patch ("commitizen.out.success" )
336300 config .settings ["allowed_prefixes" ] = ["custom!" ]
337- check_cmd = commands .Check (config = config , arguments = {"message" : "custom! test" })
338-
339- check_cmd ()
301+ commands .Check (config = config , arguments = {"message" : "custom! test" })()
340302 success_mock .assert_called_once ()
341303
342304
343- def test_check_command_override_allowed_prefixes_config (config , mocker : MockFixture ):
344- error_mock = mocker .patch ("commitizen.out.error" )
305+ def test_check_command_override_allowed_prefixes_config (config ):
345306 config .settings ["allow_abort" ] = ["fixup!" ]
346- check_cmd = commands .Check (
347- config = config ,
348- arguments = {"message" : "fixup! test" , "allowed_prefixes" : ["custom!" ]},
349- )
350-
351307 with pytest .raises (InvalidCommitMessageError ):
352- check_cmd ()
353- error_mock .assert_called_once ()
308+ commands .Check (
309+ config = config ,
310+ arguments = {"message" : "fixup! test" , "allowed_prefixes" : ["custom!" ]},
311+ )()
354312
355313
356314def test_check_command_with_pipe_message (
@@ -427,33 +385,25 @@ def test_check_conventional_commit_succeed_with_git_diff(
427385def test_check_command_with_message_length_limit (config , mocker : MockFixture ):
428386 success_mock = mocker .patch ("commitizen.out.success" )
429387 message = "fix(scope): some commit message"
430- check_cmd = commands .Check (
388+ commands .Check (
431389 config = config ,
432390 arguments = {"message" : message , "message_length_limit" : len (message ) + 1 },
433- )
434-
435- check_cmd ()
391+ )()
436392 success_mock .assert_called_once ()
437393
438394
439- def test_check_command_with_message_length_limit_exceeded (config , mocker : MockFixture ):
440- error_mock = mocker .patch ("commitizen.out.error" )
395+ def test_check_command_with_message_length_limit_exceeded (config ):
441396 message = "fix(scope): some commit message"
442- check_cmd = commands .Check (
443- config = config ,
444- arguments = {"message" : message , "message_length_limit" : len (message ) - 1 },
445- )
446-
447397 with pytest .raises (CommitMessageLengthExceededError ):
448- check_cmd ()
449- error_mock .assert_called_once ()
398+ commands .Check (
399+ config = config ,
400+ arguments = {"message" : message , "message_length_limit" : len (message ) - 1 },
401+ )()
450402
451403
452404def test_check_command_with_amend_prefix_default (config , mocker : MockFixture ):
453405 success_mock = mocker .patch ("commitizen.out.success" )
454- check_cmd = commands .Check (config = config , arguments = {"message" : "amend! test" })
455-
456- check_cmd ()
406+ commands .Check (config = config , arguments = {"message" : "amend! test" })()
457407 success_mock .assert_called_once ()
458408
459409
@@ -463,54 +413,42 @@ def test_check_command_with_config_message_length_limit(config, mocker: MockFixt
463413
464414 config .settings ["message_length_limit" ] = len (message ) + 1
465415
466- check_cmd = commands .Check (
416+ commands .Check (
467417 config = config ,
468418 arguments = {"message" : message },
469- )
419+ )()
470420
471- check_cmd ()
472421 success_mock .assert_called_once ()
473422
474423
475- def test_check_command_with_config_message_length_limit_exceeded (
476- config , mocker : MockFixture
477- ):
478- error_mock = mocker .patch ("commitizen.out.error" )
424+ def test_check_command_with_config_message_length_limit_exceeded (config ):
479425 message = "fix(scope): some commit message"
480426
481427 config .settings ["message_length_limit" ] = len (message ) - 1
482428
483- check_cmd = commands .Check (
484- config = config ,
485- arguments = {"message" : message },
486- )
487-
488429 with pytest .raises (CommitMessageLengthExceededError ):
489- check_cmd ()
490- error_mock .assert_called_once ()
430+ commands .Check (
431+ config = config ,
432+ arguments = {"message" : message },
433+ )()
491434
492435
493436def test_check_command_cli_overrides_config_message_length_limit (
494437 config , mocker : MockFixture
495438):
496- success_mock = mocker .patch ("commitizen.out.success" )
497439 message = "fix(scope): some commit message"
498-
499440 config .settings ["message_length_limit" ] = len (message ) - 1
500441
501- check_cmd = commands .Check (
502- config = config ,
503- arguments = {"message" : message , "message_length_limit" : len (message ) + 1 },
504- )
505-
506- check_cmd ()
507- success_mock .assert_called_once ()
508-
509- success_mock .reset_mock ()
510- check_cmd = commands .Check (
511- config = config ,
512- arguments = {"message" : message , "message_length_limit" : None },
513- )
442+ for message_length_limit in [len (message ) + 1 , None ]:
443+ success_mock = mocker .patch ("commitizen.out.success" )
444+ commands .Check (
445+ config = config ,
446+ arguments = {
447+ "message" : message ,
448+ "message_length_limit" : message_length_limit ,
449+ },
450+ )()
451+ success_mock .assert_called_once ()
514452
515453
516454class ValidationCz (BaseCommitizen ):
0 commit comments