16
16
from pytest_mock import MockerFixture
17
17
18
18
19
- def test_local_only (tmp_path : Path , monkeypatch : pytest . MonkeyPatch , capfd : pytest .CaptureFixture [str ]) -> None :
19
+ def test_local_only (tmp_path : Path , mocker : MockerFixture , capfd : pytest .CaptureFixture [str ]) -> None :
20
20
venv_path = str (tmp_path / "venv" )
21
21
result = virtualenv .cli_run ([venv_path , "--activators" , "" ])
22
22
venv_site_packages = site .getsitepackages ([venv_path ])
@@ -27,10 +27,11 @@ def test_local_only(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capfd: pyte
27
27
f .write ("Metadata-Version: 2.3\n " "Name: foo\n " "Version: 1.2.5\n " )
28
28
29
29
cmd = [str (result .creator .exe .parent / "python3" ), "--local-only" ]
30
- monkeypatch .setattr (sys , "prefix" , venv_path )
31
- for s in venv_site_packages :
32
- monkeypatch .syspath_prepend (s )
33
- monkeypatch .setattr (sys , "argv" , cmd )
30
+ mocker .patch ("pipdeptree._discovery.sys.prefix" , venv_path )
31
+ sys_path = sys .path .copy ()
32
+ mock_path = sys_path + venv_site_packages
33
+ mocker .patch ("pipdeptree._discovery.sys.path" , mock_path )
34
+ mocker .patch ("pipdeptree._discovery.sys.argv" , cmd )
34
35
main ()
35
36
out , _ = capfd .readouterr ()
36
37
found = {i .split ("==" )[0 ] for i in out .splitlines ()}
@@ -41,16 +42,16 @@ def test_local_only(tmp_path: Path, monkeypatch: pytest.MonkeyPatch, capfd: pyte
41
42
assert found == expected
42
43
43
44
44
- def test_user_only (tmp_path : Path , monkeypatch : pytest . MonkeyPatch , capfd : pytest .CaptureFixture [str ]) -> None :
45
+ def test_user_only (tmp_path : Path , mocker : MockerFixture , capfd : pytest .CaptureFixture [str ]) -> None :
45
46
fake_dist = Path (tmp_path ) / "foo-1.2.5.dist-info"
46
47
fake_dist .mkdir ()
47
48
fake_metadata = Path (fake_dist ) / "METADATA"
48
49
with Path (fake_metadata ).open ("w" ) as f :
49
50
f .write ("Metadata-Version: 2.3\n " "Name: foo\n " "Version: 1.2.5\n " )
50
51
51
- monkeypatch .setattr (site , "getusersitepackages" , Mock (return_value = str (tmp_path )))
52
52
cmd = [sys .executable , "--user-only" ]
53
- monkeypatch .setattr (sys , "argv" , cmd )
53
+ mocker .patch ("pipdeptree._discovery.site.getusersitepackages" , Mock (return_value = str (tmp_path )))
54
+ mocker .patch ("pipdeptree._discovery.sys.argv" , cmd )
54
55
main ()
55
56
out , _ = capfd .readouterr ()
56
57
found = {i .split ("==" )[0 ] for i in out .splitlines ()}
0 commit comments