You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/en/how-to/types.rst
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,7 +116,7 @@ While parameterized tests can involve varied data types and that annotations sim
116
116
117
117
118
118
Typing for Monkeypatching
119
-
--------------------------
119
+
-------------------------
120
120
Monkeypatching modifies functions or environment variables during runtime.
121
121
Adding typing, such as `monkeypatch: pytest.MonkeyPatch`, clarifies the expected patching behaviour and reduces the risk of errors.
122
122
@@ -177,7 +177,6 @@ Typing Temporary Directories and Paths
177
177
Temporary directories and paths are commonly used in pytest to create isolated environments for testing file and directory operations.
178
178
The `tmp_path` and `tmpdir` fixtures provide these capabilities.
179
179
Adding typing annotations enhances clarity about the types of objects these fixtures return, which is particularly useful when performing file operations.
180
-
It also prevents misuse of monkeypatch by clarifies its API and expected inputs.
181
180
182
181
Below examples are based on the pytest documentation for `Temporary Directories and Files in tests <https://github.com/pytest-dev/pytest/blob/main/doc/en/how-to/tmp_path.rst>`_, with the addition of typing annotations.
183
182
@@ -225,6 +224,7 @@ Typing `tmp_path: Path` explicitly defines it as a Path object, improving code r
225
224
# compute and test histogram
226
225
227
226
Here:
227
+
228
228
- **tmp_path_factory: pytest.TempPathFactory:** Indicates that `tmp_path_factory` is an instance of pytest’s `TempPathFactory`, responsible for creating temporary directories and paths during testing.
229
229
- **fn: Path:** Identifies that `fn` is a `Path` object, emphasizing its role as a file path and clarifying the expected file operations.
230
230
- **Return type -> Path:** Specifies the fixture returns a `Path` object, clarifying its expected structure.
0 commit comments