Skip to content

Commit a0ba4bc

Browse files
committed
refactor(test[pytest plugin]) Consolidate pytester test
1 parent e8581de commit a0ba4bc

File tree

1 file changed

+15
-72
lines changed

1 file changed

+15
-72
lines changed

tests/test_pytest_plugin.py

Lines changed: 15 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,14 @@ def test_create_svn_remote_repo(
3636
assert svn_remote_1 != svn_remote_2
3737

3838

39-
def test_create_git_remote_repo_and_git_sync(
39+
def test_git_fixtures(
4040
pytester: pytest.Pytester,
4141
monkeypatch: pytest.MonkeyPatch,
42+
tmp_path: pathlib.Path,
4243
) -> None:
43-
"""Tests pytest plugin integration for create_git_remote_repo() and GitSync()."""
44+
"""Tests for libvcs pytest plugin git configuration."""
45+
monkeypatch.setenv("HOME", str(tmp_path))
46+
4447
# Initialize variables
4548
pytester.plugins = ["pytest_plugin"]
4649
pytester.makefile(
@@ -58,6 +61,10 @@ def test_create_git_remote_repo_and_git_sync(
5861
import pathlib
5962
import pytest
6063
64+
@pytest.fixture(scope="session")
65+
def vcs_email() -> str:
66+
return "custom_email@testemail.com"
67+
6168
@pytest.fixture(autouse=True)
6269
def setup(
6370
request: pytest.FixtureRequest,
@@ -75,7 +82,11 @@ def setup(
7582
import pathlib
7683
7784
from libvcs.sync.git import GitSync
78-
from libvcs.pytest_plugin import CreateRepoPytestFixtureFn
85+
from libvcs.pytest_plugin import (
86+
CreateRepoPytestFixtureFn,
87+
git_remote_repo_single_commit_post_init
88+
)
89+
7990
8091
def test_repo_git_remote_repo_and_sync(
8192
create_git_remote_repo: CreateRepoPytestFixtureFn,
@@ -93,75 +104,7 @@ def test_repo_git_remote_repo_and_sync(
93104
94105
assert git_repo_checkout_dir.exists()
95106
assert pathlib.Path(git_repo_checkout_dir / ".git").exists()
96-
""",
97-
),
98-
}
99-
first_test_key = next(iter(files.keys()))
100-
first_test_filename = str(tests_path / first_test_key)
101-
102-
tests_path.mkdir()
103-
for file_name, text in files.items():
104-
test_file = tests_path / file_name
105-
test_file.write_text(
106-
text,
107-
encoding="utf-8",
108-
)
109-
110-
# Test
111-
result = pytester.runpytest(str(first_test_filename))
112-
result.assert_outcomes(passed=1)
113-
114-
115-
def test_git_remote_repo(
116-
pytester: pytest.Pytester,
117-
monkeypatch: pytest.MonkeyPatch,
118-
tmp_path: pathlib.Path,
119-
) -> None:
120-
"""Tests for libvcs pytest plugin git configuration."""
121-
monkeypatch.setenv("HOME", str(tmp_path))
122-
123-
# Initialize variables
124-
pytester.plugins = ["pytest_plugin"]
125-
pytester.makefile(
126-
".ini",
127-
pytest=textwrap.dedent(
128-
"""
129-
[pytest]
130-
addopts=-vv
131-
""".strip(),
132-
),
133-
)
134-
pytester.makeconftest(
135-
textwrap.dedent(
136-
r"""
137-
import pathlib
138-
import pytest
139-
140-
@pytest.fixture(scope="session")
141-
def vcs_email() -> str:
142-
return "custom_email@testemail.com"
143-
144-
@pytest.fixture(autouse=True)
145-
def setup(
146-
request: pytest.FixtureRequest,
147-
gitconfig: pathlib.Path,
148-
set_home: pathlib.Path,
149-
) -> None:
150-
pass
151-
""",
152-
),
153-
)
154-
tests_path = pytester.path / "tests"
155-
files = {
156-
"example.py": textwrap.dedent(
157-
"""
158-
import pathlib
159107
160-
from libvcs.sync.git import GitSync
161-
from libvcs.pytest_plugin import (
162-
CreateRepoPytestFixtureFn,
163-
git_remote_repo_single_commit_post_init
164-
)
165108
166109
def test_git_bare_repo_sync_and_commit(
167110
create_git_remote_bare_repo: CreateRepoPytestFixtureFn,
@@ -206,7 +149,7 @@ def test_git_bare_repo_sync_and_commit(
206149

207150
# Test
208151
result = pytester.runpytest(str(first_test_filename))
209-
result.assert_outcomes(passed=1)
152+
result.assert_outcomes(passed=2)
210153

211154

212155
def test_gitconfig(

0 commit comments

Comments
 (0)