Skip to content

Commit 2856582

Browse files
bastien31Lee-W
authored andcommitted
fix(test): set terminal width for cli tests
Force consistent terminal width for tests to avoid wrapping differences between single and multi-worker pytest modes Signed-off-by: Sebastien Fusilier <sebastien.fusilier@gmail.com>
1 parent 087580c commit 2856582

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

commitizen/cz/conventional_commits/conventional_commits.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,15 @@ def message(self, answers: ConventionalCommitsAnswers) -> str: # type: ignore[o
154154
footer = answers["footer"]
155155
is_breaking_change = answers["is_breaking_change"]
156156

157-
scope = f"({scope})" if scope else ""
158-
body = f"\n\n{body}" if body else ""
159-
title = f"{prefix}{scope}"
157+
formatted_scope = f"({scope})" if scope else ""
158+
formatted_body = f"\n\n{body}" if body else ""
159+
title = f"{prefix}{formatted_scope}"
160160
if is_breaking_change:
161161
if self.config.settings.get("breaking_change_exclamation_in_title", False):
162162
title = f"{title}!"
163-
footer = f"BREAKING CHANGE: {footer}"
163+
formatted_footter = f"\n\nBREAKING CHANGE: {footer}"
164164

165-
return f"{title}: {subject}{body}{footer}"
165+
return f"{title}: {subject}{formatted_body}{formatted_footter}"
166166

167167
def example(self) -> str:
168168
return (

tests/commands/test_version_command.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import platform
23
import sys
34

@@ -112,13 +113,25 @@ def test_version_use_version_provider(
112113
def test_version_command_shows_description_when_use_help_option(
113114
mocker: MockerFixture, capsys, file_regression
114115
):
115-
testargs = ["cz", "version", "--help"]
116-
mocker.patch.object(sys, "argv", testargs)
117-
with pytest.raises(SystemExit):
118-
cli.main()
119-
120-
out, _ = capsys.readouterr()
121-
file_regression.check(out, extension=".txt")
116+
# Force consistent terminal width for tests to avoid wrapping differences
117+
# between single and multi-worker pytest modes
118+
original_columns = os.environ.get("COLUMNS")
119+
os.environ["COLUMNS"] = "80"
120+
121+
try:
122+
testargs = ["cz", "version", "--help"]
123+
mocker.patch.object(sys, "argv", testargs)
124+
with pytest.raises(SystemExit):
125+
cli.main()
126+
127+
out, _ = capsys.readouterr()
128+
file_regression.check(out, extension=".txt")
129+
finally:
130+
# Restore original COLUMNS
131+
if original_columns is not None:
132+
os.environ["COLUMNS"] = original_columns
133+
else:
134+
os.environ.pop("COLUMNS", None)
122135

123136

124137
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)