Skip to content

Commit eea5b4d

Browse files
author
Janis
committed
Improve description
1 parent c3e2cf2 commit eea5b4d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

testing/test_mocking_file_opens.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
In order to unit test this type of situation properly we don't want to create any file on disk.
66
To do this requires mocking the `open` builtin.
77
8-
For simple cases we can use unittest.mock.patch along with unittest.mock.mock_open and we get all we need.
8+
If we need to deal with context managers for simple cases we can use unittest.mock.patch along with unittest.mock.mock_open and we get all we need.
99
1010
However if we have to iterate over the mocked `open` we have to do more work.
1111
For example say we have the following code that reads a file line by line
@@ -21,6 +21,8 @@
2121
There's some extra work that has to be done if iteration over the mocked
2222
file object is to be supported because this doesn't come as a default.
2323
Specifically we much define `__iter__` for the `mock_open function.
24+
25+
The test case in this file will show you how you can do that.
2426
"""
2527

2628
from mocking_file_opens import example_function

0 commit comments

Comments
 (0)