(
self,
*args: t.Any,
buffered: bool = False,
follow_redirects: bool = False,
**kwargs: t.Any,
)
| 202 | builder.close() |
| 203 | |
| 204 | def open( |
| 205 | self, |
| 206 | *args: t.Any, |
| 207 | buffered: bool = False, |
| 208 | follow_redirects: bool = False, |
| 209 | **kwargs: t.Any, |
| 210 | ) -> TestResponse: |
| 211 | if args and isinstance( |
| 212 | args[0], (werkzeug.test.EnvironBuilder, dict, BaseRequest) |
| 213 | ): |
| 214 | if isinstance(args[0], werkzeug.test.EnvironBuilder): |
| 215 | builder = copy(args[0]) |
| 216 | builder.environ_base = self._copy_environ(builder.environ_base or {}) # type: ignore[arg-type] |
| 217 | request = builder.get_request() |
| 218 | elif isinstance(args[0], dict): |
| 219 | request = EnvironBuilder.from_environ( |
| 220 | args[0], app=self.application, environ_base=self._copy_environ({}) |
| 221 | ).get_request() |
| 222 | else: |
| 223 | # isinstance(args[0], BaseRequest) |
| 224 | request = copy(args[0]) |
| 225 | request.environ = self._copy_environ(request.environ) |
| 226 | else: |
| 227 | # request is None |
| 228 | request = self._request_from_builder_args(args, kwargs) |
| 229 | |
| 230 | # Pop any previously preserved contexts. This prevents contexts |
| 231 | # from being preserved across redirects or multiple requests |
| 232 | # within a single block. |
| 233 | self._context_stack.close() |
| 234 | |
| 235 | response = super().open( |
| 236 | request, |
| 237 | buffered=buffered, |
| 238 | follow_redirects=follow_redirects, |
| 239 | ) |
| 240 | response.json_module = self.application.json # type: ignore[assignment] |
| 241 | |
| 242 | # Re-push contexts that were preserved during the request. |
| 243 | for cm in self._new_contexts: |
| 244 | self._context_stack.enter_context(cm) |
| 245 | |
| 246 | self._new_contexts.clear() |
| 247 | return response |
| 248 | |
| 249 | def __enter__(self) -> FlaskClient: |
| 250 | if self.preserve_context: |
no test coverage detected