Skip to content

Commit 71c37d5

Browse files
committed
test: replace legacy tmpdir with tmp_path
1 parent 2847b8c commit 71c37d5

File tree

9 files changed

+439
-413
lines changed

9 files changed

+439
-413
lines changed

tests/commands/test_bump_command.py

Lines changed: 117 additions & 119 deletions
Large diffs are not rendered by default.

tests/commands/test_changelog_command.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,22 @@
3131

3232

3333
@pytest.fixture
34-
def changelog_jinja_file(tmp_project_root: Path) -> Path:
35-
return tmp_project_root / "changelog.jinja"
34+
def changelog_jinja_file(tmp_commitizen_project: Path) -> Path:
35+
return tmp_commitizen_project / "changelog.jinja"
3636

3737

3838
@pytest.fixture
3939
def changelog_tpl(
40-
tmp_project_root: Path, any_changelog_format: ChangelogFormat
40+
tmp_commitizen_project: Path, any_changelog_format: ChangelogFormat
4141
) -> Path:
42-
return tmp_project_root / any_changelog_format.template
42+
return tmp_commitizen_project / any_changelog_format.template
4343

4444

4545
@pytest.fixture
4646
def changelog_file(
47-
tmp_project_root: Path, any_changelog_format: ChangelogFormat
47+
tmp_commitizen_project: Path, any_changelog_format: ChangelogFormat
4848
) -> Path:
49-
return tmp_project_root / any_changelog_format.default_changelog_file
49+
return tmp_commitizen_project / any_changelog_format.default_changelog_file
5050

5151

5252
@pytest.mark.usefixtures("tmp_commitizen_project")
@@ -437,7 +437,7 @@ def test_changelog_incremental_newline_separates_new_content_from_old(
437437

438438

439439
def test_changelog_without_revision(tmp_commitizen_project, util: UtilFixture):
440-
tmp_commitizen_project.join("CHANGELOG.md").write(
440+
(tmp_commitizen_project / "CHANGELOG.md").write_text(
441441
"""
442442
# Unreleased
443443
@@ -1266,7 +1266,7 @@ def test_changelog_template_option_precedence(
12661266
changelog_file: Path,
12671267
changelog_tpl: Path,
12681268
):
1269-
project_root = Path(tmp_commitizen_project)
1269+
project_root = tmp_commitizen_project
12701270
cfg_template = project_root / "changelog.cfg"
12711271
cmd_template = project_root / "changelog.cmd"
12721272

@@ -1655,7 +1655,7 @@ def test_changelog_template_incremental_variable(
16551655
Test that the changelog template is not rendered when the incremental flag is not set.
16561656
Reference: https://github.com/commitizen-tools/commitizen/discussions/1620
16571657
"""
1658-
project_root = Path(tmp_commitizen_project)
1658+
project_root = tmp_commitizen_project
16591659
changelog_tpl = project_root / any_changelog_format.template
16601660
changelog_tpl.write_text(
16611661
dedent("""

tests/commands/test_check_command.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ def test_check_conventional_commit_succeeds(
119119
),
120120
],
121121
)
122-
def test_check_no_conventional_commit(commit_msg, config, tmpdir):
123-
tempfile = tmpdir.join("temp_commit_file")
124-
tempfile.write(commit_msg)
122+
def test_check_no_conventional_commit(commit_msg, config, tmp_path):
123+
tempfile = tmp_path / "temp_commit_file"
124+
tempfile.write_text(commit_msg)
125125

126126
with pytest.raises(InvalidCommitMessageError):
127127
commands.Check(config=config, arguments={"commit_msg_file": tempfile})()
@@ -136,9 +136,11 @@ def test_check_no_conventional_commit(commit_msg, config, tmpdir):
136136
"bump: 0.0.1 -> 1.0.0",
137137
],
138138
)
139-
def test_check_conventional_commit(commit_msg, config, success_mock: MockType, tmpdir):
140-
tempfile = tmpdir.join("temp_commit_file")
141-
tempfile.write(commit_msg)
139+
def test_check_conventional_commit(
140+
commit_msg, config, success_mock: MockType, tmp_path
141+
):
142+
tempfile = tmp_path / "temp_commit_file"
143+
tempfile.write_text(commit_msg)
142144
commands.Check(config=config, arguments={"commit_msg_file": tempfile})()
143145
success_mock.assert_called_once()
144146

tests/commands/test_commit_command.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ def staging_is_clean(mocker: MockFixture, tmp_git_project):
5151
@pytest.fixture
5252
def backup_file(tmp_git_project, monkeypatch):
5353
"""Write backup message so Commit finds it when run from tmp_git_project."""
54-
with tmp_git_project.as_cwd():
55-
path = get_backup_file_path()
56-
path.write_text("backup commit", encoding="utf-8")
5754
monkeypatch.chdir(tmp_git_project)
55+
path = get_backup_file_path()
56+
path.write_text("backup commit", encoding="utf-8")
5857

5958

6059
@pytest.mark.usefixtures("staging_is_clean", "commit_mock", "prompt_mock_feat")
@@ -263,10 +262,10 @@ def test_commit_when_no_user_answer(config, mocker: MockFixture):
263262
commands.Commit(config, {})()
264263

265264

266-
def test_commit_in_non_git_project(tmpdir, config):
267-
with tmpdir.as_cwd():
268-
with pytest.raises(NotAGitProjectError):
269-
commands.Commit(config, {})
265+
def test_commit_in_non_git_project(tmp_path, monkeypatch, config):
266+
monkeypatch.chdir(tmp_path)
267+
with pytest.raises(NotAGitProjectError):
268+
commands.Commit(config, {})
270269

271270

272271
@pytest.mark.usefixtures("staging_is_clean", "commit_mock", "prompt_mock_feat")

0 commit comments

Comments
 (0)