Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2d12337

Browse files
committed
test(tests/conftest): move tmp_git_project and tmp_commitizen_project into conftest
they're commonly used fixture among all tests
1 parent a85a48c commit 2d12337

File tree

3 files changed

+25
-29
lines changed

3 files changed

+25
-29
lines changed

tests/commands/test_bump_command.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,6 @@
88
from commitizen import cli, cmd, git
99

1010

11-
@pytest.fixture(scope="function")
12-
def tmp_git_project(tmpdir):
13-
with tmpdir.as_cwd():
14-
with open("pyproject.toml", "w") as f:
15-
f.write("[tool.commitizen]\n" 'version="0.1.0"')
16-
17-
cmd.run("git init")
18-
19-
yield
20-
21-
2211
def create_file_and_commit(message: str, filename: Optional[str] = None):
2312
if not filename:
2413
filename = str(uuid.uuid4())
@@ -28,7 +17,7 @@ def create_file_and_commit(message: str, filename: Optional[str] = None):
2817
git.commit(message)
2918

3019

31-
@pytest.mark.usefixtures("tmp_git_project")
20+
@pytest.mark.usefixtures("tmp_commitizen_project")
3221
def test_bump_command(mocker):
3322
# MINOR
3423
create_file_and_commit("feat: new file")
@@ -101,13 +90,12 @@ def test_bump_when_bumpping_is_not_support(mocker, capsys, tmpdir):
10190
assert "'cz_jira' rule does not support bump" in err
10291

10392

104-
def test_bump_is_not_specify(mocker, capsys, tmpdir):
93+
@pytest.mark.usefixtures("tmp_git_project")
94+
def test_bump_is_not_specify(mocker, capsys):
10595
mocker.patch.object(sys, "argv", ["cz", "bump"])
10696

10797
with pytest.raises(SystemExit):
108-
with tmpdir.as_cwd():
109-
cmd.run("git init")
110-
cli.main()
98+
cli.main()
11199

112100
expected_error_message = (
113101
"[NO_VERSION_SPECIFIED]\n"
@@ -119,7 +107,8 @@ def test_bump_is_not_specify(mocker, capsys, tmpdir):
119107
assert expected_error_message in err
120108

121109

122-
def test_bump_when_not_new_commit(mocker, capsys, tmp_git_project):
110+
@pytest.mark.usefixtures("tmp_commitizen_project")
111+
def test_bump_when_not_new_commit(mocker, capsys):
123112
testargs = ["cz", "bump", "--yes"]
124113
mocker.patch.object(sys, "argv", testargs)
125114

tests/conftest.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import pytest
2+
3+
from commitizen import cmd
4+
5+
6+
@pytest.fixture(scope="function")
7+
def tmp_git_project(tmpdir):
8+
with tmpdir.as_cwd():
9+
cmd.run("git init")
10+
11+
yield
12+
13+
14+
@pytest.fixture(scope="function")
15+
@pytest.mark.usefixtures("tmp_git_project")
16+
def tmp_commitizen_project(tmp_git_project):
17+
with open("pyproject.toml", "w") as f:
18+
f.write("[tool.commitizen]\n" 'version="0.1.0"')

tests/test_cli.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,10 @@
22

33
import pytest
44

5-
from commitizen import cli, cmd
5+
from commitizen import cli
66
from commitizen.__version__ import __version__
77

88

9-
@pytest.fixture(scope="function")
10-
def tmp_git_project(tmpdir):
11-
with tmpdir.as_cwd():
12-
with open("pyproject.toml", "w") as f:
13-
f.write("[tool.commitizen]\n" 'version="0.1.0"')
14-
15-
cmd.run("git init")
16-
17-
yield
18-
19-
209
def test_sysexit_no_argv(mocker, capsys):
2110
testargs = ["cz"]
2211
mocker.patch.object(sys, "argv", testargs)

0 commit comments

Comments
 (0)