Perform the following in order: pre-setup, run test, post-teardown, skipping pre/post hooks if test is set to be skipped. If debug=True, reraise any errors in setup and use super().debug() instead of __call__() to run the test.
(self, result, debug=False)
| 336 | self._setup_and_call(debug_result, debug=True) |
| 337 | |
| 338 | def _setup_and_call(self, result, debug=False): |
| 339 | """ |
| 340 | Perform the following in order: pre-setup, run test, post-teardown, |
| 341 | skipping pre/post hooks if test is set to be skipped. |
| 342 | |
| 343 | If debug=True, reraise any errors in setup and use super().debug() |
| 344 | instead of __call__() to run the test. |
| 345 | """ |
| 346 | testMethod = getattr(self, self._testMethodName) |
| 347 | skipped = getattr(self.__class__, "__unittest_skip__", False) or getattr( |
| 348 | testMethod, "__unittest_skip__", False |
| 349 | ) |
| 350 | |
| 351 | # Convert async test methods. |
| 352 | if iscoroutinefunction(testMethod): |
| 353 | setattr(self, self._testMethodName, async_to_sync(testMethod)) |
| 354 | |
| 355 | if not skipped: |
| 356 | try: |
| 357 | if self.__class__._pre_setup_ran_eagerly: |
| 358 | self.__class__._pre_setup_ran_eagerly = False |
| 359 | else: |
| 360 | self._pre_setup() |
| 361 | except Exception: |
| 362 | if debug: |
| 363 | raise |
| 364 | result.addError(self, sys.exc_info()) |
| 365 | return |
| 366 | if debug: |
| 367 | super().debug() |
| 368 | else: |
| 369 | super().__call__(result) |
| 370 | if not skipped: |
| 371 | try: |
| 372 | self._post_teardown() |
| 373 | except Exception: |
| 374 | if debug: |
| 375 | raise |
| 376 | result.addError(self, sys.exc_info()) |
| 377 | return |
| 378 | |
| 379 | @classmethod |
| 380 | def _pre_setup(cls): |
no test coverage detected