Skip to content

Commit a4cf7b0

Browse files
Test installing usethis in the venv it manages (#236)
* Test installing usethis in the venv it manages * Change dir structure
1 parent 61fc24c commit a4cf7b0

2 files changed

Lines changed: 55 additions & 0 deletions

File tree

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,8 @@ def _vary_network_conn(request: pytest.FixtureRequest) -> Generator[None, None,
6161
usethis_config.offline = offline
6262
yield
6363
usethis_config.offline = False
64+
65+
66+
@pytest.fixture
67+
def usethis_dev_dir() -> Path:
68+
return Path(__file__).parent.parent

tests/test_install.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import shutil
2+
from collections.abc import Generator
3+
from pathlib import Path
4+
from tempfile import TemporaryDirectory
5+
6+
import pytest
7+
8+
from usethis._integrations.uv.call import call_uv_subprocess
9+
from usethis._subprocess import call_subprocess
10+
from usethis._test import change_cwd
11+
12+
13+
@pytest.fixture
14+
def usethis_installed_dir(
15+
uv_init_dir: Path, usethis_dev_dir: Path
16+
) -> Generator[Path, None, None]:
17+
with TemporaryDirectory() as tmp_path:
18+
# Make a copy of the current usethis codebase to avoid interacting with pytest
19+
copy_usethis_dev_dir = Path(tmp_path) / "usethis-python"
20+
shutil.copytree(
21+
usethis_dev_dir,
22+
copy_usethis_dev_dir,
23+
# The git repo is too big and we don't need it
24+
ignore=shutil.ignore_patterns(".git"),
25+
)
26+
27+
with change_cwd(copy_usethis_dev_dir):
28+
# Initialize a git repository so the package can be built (since it relies
29+
# on vcs)
30+
call_subprocess(["git", "init"])
31+
call_subprocess(["git", "add", "."])
32+
call_subprocess(["git", "commit", "-m", "Initial commit"])
33+
34+
with change_cwd(uv_init_dir):
35+
# Install usethis in a virtual environment
36+
call_uv_subprocess(["add", f"{copy_usethis_dev_dir.as_posix()}"])
37+
38+
yield uv_init_dir
39+
40+
41+
class TestInstalledInOwnVenv:
42+
def test_help(self, usethis_installed_dir):
43+
with change_cwd(usethis_installed_dir):
44+
# Should run without error
45+
call_subprocess(["usethis", "--help"])
46+
47+
def test_add_pytest(self, usethis_installed_dir):
48+
with change_cwd(usethis_installed_dir):
49+
# Should run without error
50+
call_subprocess(["usethis", "tool", "pytest"])

0 commit comments

Comments
 (0)