bpo-36674: Stops skipped tests from running in debug mode. by lisroach · Pull Request #13180 · python/cpython
It seems that TestCase.run() implementation uses the testPartExecutor context manager. It does so to wrap exceptions (and skips) raised in either setUp, the test method or tearDown calls:
| with outcome.testPartExecutor(self): | |
| self._callSetUp() | |
| if outcome.success: | |
| outcome.expecting_failure = expecting_failure | |
| with outcome.testPartExecutor(self, isTest=True): | |
| self._callTestMethod(testMethod) | |
| outcome.expecting_failure = False | |
| with outcome.testPartExecutor(self): | |
| self._callTearDown() |
With this in mind, and considering the docs would it make more sense to wrap in try/except like this:
def debug(self): """Run the test without collecting errors in a TestResult""" try: self.setUp() getattr(self, self._testMethodName)() self.tearDown() except SkipError: pass while self._cleanups: function, args, kwargs = self._cleanups.pop(-1) function(*args, **kwargs)
Note: users and developers of pytest have been struggling with understanding the TestCase.debug() interface and use case for a while (with regards to launching postmortem, teardown and skipping). Here's one of the relevant ones: pytest-dev/pytest-django#772