12
12
13
13
if TYPE_CHECKING :
14
14
from _pytest .logging import LogCaptureFixture
15
+ from pytest_mock import MockerFixture
16
+
15
17
16
18
DIST_PATH = Path (__file__ ).parent .parent / "fixtures" / "distributions"
17
19
SAMPLE_PROJECT = Path (__file__ ).parent .parent / "fixtures" / "sample_project"
18
20
19
21
20
- def test_directory_dependency_does_not_exist (caplog : LogCaptureFixture ) -> None :
22
+ def test_directory_dependency_does_not_exist (
23
+ caplog : LogCaptureFixture , mocker : MockerFixture
24
+ ) -> None :
25
+ mock_exists = mocker .patch .object (Path , "exists" )
26
+ mock_exists .return_value = False
21
27
dep = DirectoryDependency ("demo" , DIST_PATH / "invalid" )
22
28
assert len (caplog .records ) == 1
23
29
record = caplog .records [0 ]
@@ -27,8 +33,14 @@ def test_directory_dependency_does_not_exist(caplog: LogCaptureFixture) -> None:
27
33
with pytest .raises (ValueError , match = "does not exist" ):
28
34
dep .validate (raise_error = True )
29
35
36
+ mock_exists .assert_called_once ()
37
+
30
38
31
- def test_directory_dependency_is_file (caplog : LogCaptureFixture ) -> None :
39
+ def test_directory_dependency_is_file (
40
+ caplog : LogCaptureFixture , mocker : MockerFixture
41
+ ) -> None :
42
+ mock_is_file = mocker .patch .object (Path , "is_file" )
43
+ mock_is_file .return_value = True
32
44
dep = DirectoryDependency ("demo" , DIST_PATH / "demo-0.1.0.tar.gz" )
33
45
assert len (caplog .records ) == 1
34
46
record = caplog .records [0 ]
@@ -38,6 +50,8 @@ def test_directory_dependency_is_file(caplog: LogCaptureFixture) -> None:
38
50
with pytest .raises (ValueError , match = "is a file" ):
39
51
dep .validate (raise_error = True )
40
52
53
+ mock_is_file .assert_called_once ()
54
+
41
55
42
56
def test_directory_dependency_is_not_a_python_project (
43
57
caplog : LogCaptureFixture ,
0 commit comments