Skip to content

Commit f139592

Browse files
committed
adding support for patch
1 parent edb4631 commit f139592

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

test_pytest_mock.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,28 +55,30 @@ def ls(cls, path):
5555

5656
@pytest.fixture
5757
def check_unix_fs_mocked(tmpdir, mock):
58-
def check(mocked_rm):
59-
(tmpdir / 'foo.txt').ensure()
60-
UnixFS.rm(tmpdir / 'foo.txt')
61-
os.remove.assert_called_once_with(tmpdir / 'foo.txt')
62-
mocked_rm.assert_called_once_with(tmpdir / 'foo.txt')
63-
assert os.path.isfile(str(tmpdir / 'foo.txt'))
58+
def check(mocked_rm, mocked_ls):
59+
file_name = tmpdir / 'foo.txt'
60+
file_name.ensure()
61+
UnixFS.rm(str(file_name))
62+
os.remove.assert_called_once_with(str(file_name))
63+
mocked_rm.assert_called_once_with(str(file_name))
64+
assert os.path.isfile(str(file_name))
6465
mock.stopall()
65-
UnixFS.rm(str(tmpdir / 'foo.txt'))
66-
assert not os.path.isfile(str(tmpdir / 'foo.txt'))
66+
UnixFS.rm(str(file_name))
67+
assert not os.path.isfile(str(file_name))
6768

6869
return check
6970

7071

7172
def mock_using_patch_object(mock):
72-
return mock.patch.object(os, 'remove')
73+
return mock.patch.object(os, 'remove'), mock.patch.object(os, 'listdir')
74+
7375

7476
def mock_using_patch(mock):
75-
return mock.patch('os.remove')
77+
return mock.patch('os.remove'), mock.patch('os.listdir')
78+
7679

7780
@pytest.mark.parametrize('mock_fs', [mock_using_patch_object, mock_using_patch],
7881
)
7982
def test_fixture(mock_fs, mock, check_unix_fs_mocked):
80-
mocked_rm = mock_fs(mock)
81-
#mocked_rm = mock.patch(os, 'remove')
82-
check_unix_fs_mocked(mocked_rm)
83+
mocked_rm, mocked_ls = mock_fs(mock)
84+
check_unix_fs_mocked(mocked_rm, mocked_ls)

0 commit comments

Comments
 (0)