1- import os
21import sys
32from pathlib import Path
43from textwrap import dedent
@@ -29,20 +28,19 @@ def test_create_tag(test_input, expected):
2928
3029
3130@pytest .mark .parametrize ("retry" , (True , False ))
32- def test_bump_pre_commit_changelog (
33- tmp_commitizen_project , mocker : MockFixture , freezer , retry
34- ):
31+ @pytest .mark .usefixtures ("tmp_commitizen_project" )
32+ def test_bump_pre_commit_changelog (mocker : MockFixture , freezer , retry ):
3533 freezer .move_to ("2022-04-01" )
3634 testargs = ["cz" , "bump" , "--changelog" , "--yes" ]
3735 if retry :
3836 testargs .append ("--retry" )
3937 else :
4038 pytest .xfail ("it will fail because pre-commit will reformat CHANGELOG.md" )
4139 mocker .patch .object (sys , "argv" , testargs )
42- with tmp_commitizen_project . as_cwd ():
43- # Configure prettier as a pre-commit hook
44- Path ( ".pre-commit-config.yaml" ). write_text (
45- """
40+ # Configure prettier as a pre-commit hook
41+ Path ( ". pre-commit-config.yaml" ). write_text (
42+ dedent (
43+ """\
4644 repos:
4745 - repo: https://github.com/pre-commit/mirrors-prettier
4846 rev: v2.6.2
@@ -51,44 +49,43 @@ def test_bump_pre_commit_changelog(
5149 stages: [commit]
5250 """
5351 )
54- # Prettier inherits editorconfig
55- Path (".editorconfig" ).write_text (
56- """
52+ )
53+ # Prettier inherits editorconfig
54+ Path (".editorconfig" ).write_text (
55+ dedent (
56+ """\
5757 [*]
5858 indent_size = 4
5959 """
6060 )
61- cmd .run ("git add -A" )
62- if os .name == "nt" :
63- cmd .run ('git commit -m "fix: _test"' )
64- else :
65- cmd .run ("git commit -m 'fix: _test'" )
66- cmd .run ("pre-commit install" )
67- cli .main ()
68- # Pre-commit fixed last line adding extra indent and "\" char
69- assert Path ("CHANGELOG.md" ).read_text () == dedent (
70- """\
71- ## 0.1.1 (2022-04-01)
61+ )
62+ cmd .run ("git add -A" )
63+ cmd .run ('git commit -m "fix: _test"' )
64+ cmd .run ("pre-commit install" )
65+ cli .main ()
66+ # Pre-commit fixed last line adding extra indent and "\" char
67+ assert Path ("CHANGELOG.md" ).read_text () == dedent (
68+ """\
69+ ## 0.1.1 (2022-04-01)
7270
73- ### Fix
71+ ### Fix
7472
75- - \\ _test
76- """
77- )
73+ - \\ _test
74+ """
75+ )
7876
7977
8078@pytest .mark .parametrize ("retry" , (True , False ))
81- def test_bump_pre_commit_changelog_fails_always (
82- tmp_commitizen_project , mocker : MockFixture , freezer , retry
83- ):
79+ @pytest .mark .usefixtures ("tmp_commitizen_project" )
80+ def test_bump_pre_commit_changelog_fails_always (mocker : MockFixture , freezer , retry ):
8481 freezer .move_to ("2022-04-01" )
8582 testargs = ["cz" , "bump" , "--changelog" , "--yes" ]
8683 if retry :
8784 testargs .append ("--retry" )
8885 mocker .patch .object (sys , "argv" , testargs )
89- with tmp_commitizen_project . as_cwd ():
90- Path ( ".pre-commit-config.yaml" ). write_text (
91- """
86+ Path ( ".pre-commit-config.yaml" ). write_text (
87+ dedent (
88+ """\
9289 repos:
9390 - repo: local
9491 hooks:
@@ -99,11 +96,9 @@ def test_bump_pre_commit_changelog_fails_always(
9996 files: CHANGELOG.md
10097 """
10198 )
102- cmd .run ("git add -A" )
103- if os .name == "nt" :
104- cmd .run ('git commit -m "feat: forbid changelogs"' )
105- else :
106- cmd .run ("git commit -m 'feat: forbid changelogs'" )
107- cmd .run ("pre-commit install" )
108- with pytest .raises (exceptions .BumpCommitFailedError ):
109- cli .main ()
99+ )
100+ cmd .run ("git add -A" )
101+ cmd .run ('git commit -m "feat: forbid changelogs"' )
102+ cmd .run ("pre-commit install" )
103+ with pytest .raises (exceptions .BumpCommitFailedError ):
104+ cli .main ()
0 commit comments