-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to skip unittests if --pdb active #2225
Allow to skip unittests if --pdb active #2225
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks pretty good, thanks @mbyt for contributing again! 👍
_pytest/unittest.py
Outdated
@@ -157,9 +156,20 @@ def runtest(self): | |||
self._testcase(result=self) | |||
else: | |||
# disables tearDown and cleanups for post mortem debugging (see #1890) | |||
# but still implements the skipping machinery (see #2137) | |||
testMethod = getattr(self._testcase, self._testcase._testMethodName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks correct according to the implementation in unittest
, thanks!
Could you please move this entire logic to a separate method though? Something like:
...
else:
if self._handle_skip():
return
self._testcase.debug()
This makes the code easier to follow IMHO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea, that makes it much easier to read. I did that in ad56cd8.
_pytest/unittest.py
Outdated
# If the class or method was skipped. | ||
skip_why = (getattr(self._testcase.__class__, '__unittest_skip_why__', '') or | ||
getattr(testMethod, '__unittest_skip_why__', '')) | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend making an explicit version check here; try/except (specially on a generic exception like TypeError
) can catch the exception on some unintended part of the code, making it hard to understand/debug the problem.
In short:
if sys.version_info[0] == 3:
self._testcase._addSkip(self, self._testcase, skip_why)
else:
self._testcase._addSkip(self, skip_why)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nicoddemus that was intentionally, as the python3 _addSkip
has the same signature as the unittest2 _addSkip
on python2, see here.
However, it was implicit. I explicitly added a comment and secured the PY2 path in 176c680.
(Resolved the changelog conflict directly on the GH interface, that's neat!) |
skip_why = (getattr(self._testcase.__class__, '__unittest_skip_why__', '') or | ||
getattr(testMethod, '__unittest_skip_why__', '')) | ||
try: # PY3, unittest2 on PY2 | ||
self._testcase._addSkip(self, self._testcase, skip_why) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @mbyt, now I see that it is support both unittest
and unittest2
on Python 2.
A try/except for TypeError still makes me uneasy, but I have no better suggestion so let's go with it. 👍
If somebody would like more time to review this please let me know, otherwise I plan to merge this tomorrow evening. |
Thanks again @mbyt! |
One solution for #2137