1414from commitizen .config .yaml_config import YAMLConfig
1515from commitizen .exceptions import ConfigFileIsEmpty , InvalidConfigurationError
1616
17- PYPROJECT = """
17+ TOML_STR = """
1818[tool.commitizen]
1919name = "cz_jira"
2020version = "1.0.0"
3030 "scripts/generate_documentation.sh"
3131]
3232post_bump_hooks = ["scripts/slack_notification.sh"]
33+ """
34+
35+ PYPROJECT = f"""
36+ { TOML_STR }
3337
3438[tool.black]
3539line-length = 88
3640target-version = ['py36', 'py37', 'py38']
3741"""
3842
43+
3944DICT_CONFIG = {
4045 "commitizen" : {
4146 "name" : "cz_jira" ,
@@ -184,34 +189,34 @@ class TestReadCfg:
184189 @pytest .mark .parametrize (
185190 "config_files_manager" , defaults .CONFIG_FILES , indirect = True
186191 )
187- def test_load_conf (_ , config_files_manager ):
192+ def test_load_conf (self , config_files_manager ):
188193 cfg = config .read_cfg ()
189194 assert cfg .settings == _settings
190195
191- def test_conf_returns_default_when_no_files (_ , tmpdir ):
196+ def test_conf_returns_default_when_no_files (self , tmpdir ):
192197 with tmpdir .as_cwd ():
193198 cfg = config .read_cfg ()
194199 assert cfg .settings == defaults .DEFAULT_SETTINGS
195200
196- def test_load_empty_pyproject_toml_and_cz_toml_with_config (_ , tmpdir ):
201+ def test_load_empty_pyproject_toml_and_cz_toml_with_config (self , tmpdir ):
197202 with tmpdir .as_cwd ():
198203 p = tmpdir .join ("pyproject.toml" )
199204 p .write ("" )
200205 p = tmpdir .join (".cz.toml" )
201- p .write (PYPROJECT )
206+ p .write (TOML_STR )
202207
203208 cfg = config .read_cfg ()
204209 assert cfg .settings == _settings
205210
206- def test_load_pyproject_toml_from_config_argument (_ , tmpdir ):
211+ def test_load_pyproject_toml_from_config_argument (self , tmpdir ):
207212 with tmpdir .as_cwd ():
208213 _not_root_path = tmpdir .mkdir ("not_in_root" ).join ("pyproject.toml" )
209214 _not_root_path .write (PYPROJECT )
210215
211216 cfg = config .read_cfg (filepath = "./not_in_root/pyproject.toml" )
212217 assert cfg .settings == _settings
213218
214- def test_load_cz_json_not_from_config_argument (_ , tmpdir ):
219+ def test_load_cz_json_not_from_config_argument (self , tmpdir ):
215220 with tmpdir .as_cwd ():
216221 _not_root_path = tmpdir .mkdir ("not_in_root" ).join (".cz.json" )
217222 _not_root_path .write (JSON_STR )
@@ -220,7 +225,7 @@ def test_load_cz_json_not_from_config_argument(_, tmpdir):
220225 json_cfg_by_class = JsonConfig (data = JSON_STR , path = _not_root_path )
221226 assert cfg .settings == json_cfg_by_class .settings
222227
223- def test_load_cz_yaml_not_from_config_argument (_ , tmpdir ):
228+ def test_load_cz_yaml_not_from_config_argument (self , tmpdir ):
224229 with tmpdir .as_cwd ():
225230 _not_root_path = tmpdir .mkdir ("not_in_root" ).join (".cz.yaml" )
226231 _not_root_path .write (YAML_STR )
@@ -229,7 +234,7 @@ def test_load_cz_yaml_not_from_config_argument(_, tmpdir):
229234 yaml_cfg_by_class = YAMLConfig (data = YAML_STR , path = _not_root_path )
230235 assert cfg .settings == yaml_cfg_by_class ._settings
231236
232- def test_load_empty_pyproject_toml_from_config_argument (_ , tmpdir ):
237+ def test_load_empty_pyproject_toml_from_config_argument (self , tmpdir ):
233238 with tmpdir .as_cwd ():
234239 _not_root_path = tmpdir .mkdir ("not_in_root" ).join ("pyproject.toml" )
235240 _not_root_path .write ("" )
@@ -240,27 +245,25 @@ def test_load_empty_pyproject_toml_from_config_argument(_, tmpdir):
240245
241246class TestWarnMultipleConfigFiles :
242247 @pytest .mark .parametrize (
243- "files,expected_path,should_warn " ,
248+ "files,expected_path" ,
244249 [
245250 # Same directory, different file types
246- ([(".cz.toml" , PYPROJECT ), (".cz.json" , JSON_STR )], ".cz.toml" , True ),
247- ([(".cz.json" , JSON_STR ), (".cz.yaml" , YAML_STR )], ".cz.json" , True ),
248- ([(".cz.toml" , PYPROJECT ), (".cz.yaml" , YAML_STR )], ".cz.toml" , True ),
249- # With pyproject.toml (excluded from warning)
251+ ([(".cz.toml" , TOML_STR ), (".cz.json" , JSON_STR )], ".cz.toml" ),
252+ ([(".cz.json" , JSON_STR ), (".cz.yaml" , YAML_STR )], ".cz.json" ),
253+ ([(".cz.toml" , TOML_STR ), (".cz.yaml" , YAML_STR )], ".cz.toml" ),
254+ # With pyproject.toml
250255 (
251256 [("pyproject.toml" , PYPROJECT ), (".cz.json" , JSON_STR )],
252257 ".cz.json" ,
253- False ,
254258 ),
255259 (
256- [("pyproject.toml" , PYPROJECT ), (".cz.toml" , PYPROJECT )],
260+ [("pyproject.toml" , PYPROJECT ), (".cz.toml" , TOML_STR )],
257261 ".cz.toml" ,
258- False ,
259262 ),
260263 ],
261264 )
262265 def test_warn_multiple_config_files_same_dir (
263- _ , tmpdir , capsys , files , expected_path , should_warn
266+ _ , tmpdir , capsys , files , expected_path
264267 ):
265268 """Test warning when multiple config files exist in same directory."""
266269 with tmpdir .as_cwd ():
@@ -270,27 +273,20 @@ def test_warn_multiple_config_files_same_dir(
270273 cfg = config .read_cfg ()
271274 captured = capsys .readouterr ()
272275
273- if should_warn :
274- assert "Multiple config files detected" in captured .err
275- assert "Using" in captured .err
276- for filename , _ in files :
277- if filename != "pyproject.toml" :
278- assert filename in captured .err
279- else :
280- assert "Multiple config files detected" not in captured .err
276+ assert "Multiple config files detected" in captured .err
277+ for filename , _ in files :
278+ assert filename in captured .err
279+ assert f"Using config file: '{ expected_path } '" in captured .err
281280
282281 assert cfg .path == Path (expected_path )
283- # Verify config loaded correctly (name and version match expected)
284- assert cfg .settings ["name" ] == "cz_jira"
285- assert cfg .settings ["version" ] == "1.0.0"
286282
287283 @pytest .mark .parametrize (
288284 "config_file,content" ,
289285 [
290286 (".cz.json" , JSON_STR ),
291- (".cz.toml" , PYPROJECT ),
287+ (".cz.toml" , TOML_STR ),
292288 (".cz.yaml" , YAML_STR ),
293- ("cz.toml" , PYPROJECT ),
289+ ("cz.toml" , TOML_STR ),
294290 ("cz.json" , JSON_STR ),
295291 ("cz.yaml" , YAML_STR ),
296292 ],
@@ -317,7 +313,7 @@ def test_warn_same_filename_different_directories_with_git(
317313 assert f"Using config file: '{ config_file } '" in captured .err
318314 assert cfg .path == Path (config_file )
319315
320- def test_no_warn_with_explicit_config_path (_ , tmpdir , capsys ):
316+ def test_no_warn_with_explicit_config_path (self , tmpdir , capsys ):
321317 """Test that no warning is issued when user explicitly specifies config."""
322318 with tmpdir .as_cwd ():
323319 # Create multiple config files
@@ -340,11 +336,11 @@ def test_no_warn_with_explicit_config_path(_, tmpdir, capsys):
340336 [
341337 (file , content , with_git )
342338 for file , content in [
343- (".cz.toml" , PYPROJECT ),
339+ (".cz.toml" , TOML_STR ),
344340 (".cz.json" , JSON_STR ),
345341 (".cz.yaml" , YAML_STR ),
346342 ("pyproject.toml" , PYPROJECT ),
347- ("cz.toml" , PYPROJECT ),
343+ ("cz.toml" , TOML_STR ),
348344 ("cz.json" , JSON_STR ),
349345 ("cz.yaml" , YAML_STR ),
350346 ]
@@ -368,6 +364,18 @@ def test_no_warn_with_single_config_file(
368364 assert "Multiple config files detected" not in captured .err
369365 assert cfg .path == Path (config_file )
370366
367+ def test_no_warn_with_no_commitizen_section_in_pyproject_toml_and_cz_toml (
368+ _ , tmpdir , capsys
369+ ):
370+ with tmpdir .as_cwd ():
371+ tmpdir .join ("pyproject.toml" ).write ("[tool.foo]\n bar = 'baz'" )
372+ tmpdir .join (".cz.toml" ).write (TOML_STR )
373+
374+ cfg = config .read_cfg ()
375+ captured = capsys .readouterr ()
376+ assert "Multiple config files detected" not in captured .err
377+ assert cfg .path == Path (".cz.toml" )
378+
371379
372380@pytest .mark .parametrize (
373381 "config_file" ,
0 commit comments