-
-
Notifications
You must be signed in to change notification settings - Fork 32.7k
Fixed #27391 -- Implemented SimpleTestCase.debug(). #7436
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
Conversation
bb410ca
to
770250d
Compare
Did you consider trying to factor the shared logic with |
I was really trying to avoid it, I'd hate to see current simplicity get bogged down... but, how about this: def _setup_and_call(self, result=None, debug=False):
"""
Wrapper around default __call__ method to perform common Django test
set up. This means that user-defined Test Cases aren't required to
include a call to super().setUp().
If passed debug=True, does does not catch errors and calls super().debug
instead of __call__.
"""
testMethod = getattr(self, self._testMethodName)
skipped = (
getattr(self.__class__, "__unittest_skip__", False) or
getattr(testMethod, "__unittest_skip__", False))
if not skipped:
try:
self._pre_setup()
except Exception:
result.addError(self, sys.exc_info())
if debug:
raise
return
if debug:
super(SimpleTestCase, self).debug()
else:
super(SimpleTestCase, self).__call__(result)
if not skipped:
try:
self._post_teardown()
except Exception:
result.addError(self, sys.exc_info())
if debug:
raise
return We can refactor this into smaller components obviously, if you prefer. Update: simplified by removing contextmanager, it's actually shorter and avoids a bug where test is executed even if setup failed. Update2: also found and amended an issue with running the skip test since in debug it raised SkipTest. Pushed again to run test suite. |
d1f2eae
to
cc1c99a
Compare
@timgraham please take a look at the updated code. Is this more or less what you envisioned? Or would you like anything changed here? Also, should we mention this in docs/changelog ? |
cc1c99a
to
a98dcfa
Compare
a98dcfa
to
71f86c3
Compare
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 pushed a few updates -- some clean up remains if you could polish. Try to split the tests up rather than having one bit test. The tests that don't involve debug()
are probably already passing before this change and so could be added in a separate commit that precedes the commit that adds debug()
.
@asfaltboy, do you have any time and interest in completing this soon? |
b32f154
to
0de4393
Compare
Hi @timgraham sorry for taking long to respond (and for hogging the CI machine with amends). How does the test case look now? |
It looks like there's a test isolation problem (see the build failures). |
Thanks @timgraham I'll try to address it later today or this week. Time constraints, sorry ... |
71cd053
to
40f0517
Compare
@timgraham it took "a bit" longer than promised, but I finally got to it. The isolation issue was due to raised exception in Debug requiring to properly cleaning up after we're done with suite. It's not a coincidence, because this is exactly what the fix intends to do, to let the test running framework (e.g pytest) to be able to catch errors and do their own cleanup as desired. |
Other than the exception issue above, this looks good to me. Perhaps this deserves an entry in the release notes? |
@timmartin I added a commit & comment for the mentioned case. About updating release notes, I think we can rebase this PR over latest master and add this under 2.0.txt: Miscellaneous (currently line 634): +* Implement the ``SimpleTestCase.debug()`` method to allow a test to run without
+ collecting the result. This allows exceptions raised by the test to be propagated to
+ the caller, and is used to support running tests under a debugger.
+ (:ticket:`27391`). |
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.
Test coverage seems lacking as I commented out the two
if debug:
raise
blocks and don't see any test failures.
4bad9e7
to
bbfcf5b
Compare
Hi @timmartin @timgraham , I've had some time during the europython event to address the requested changes. I've had to move the addError call to under the raise call in both pre-set and post-teardown clauses (which makes sense) and added tests for those. The sqlite3-windows tests were failing on CI so I rebased (maybe un-necessarily) and now the sqlite3-bionic test is failing. Is this unrelated? |
Now I can comment both Yes, the build failure is unrelated. Don't worry about that. |
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.
Looks good, can we get this merged @Ian-Foote
This probably needs rebasing first, so it can be re-tested. |
bbfcf5b
to
be50796
Compare
@Ian-Foote @LuRsT thanks for your interest in merging this PR, it motivated me to get back to it. I went ahead and rebased over latest master, and addressed the missing tests mentioned by @timgraham. These tests validate that the existing TestCase behavior, of capturing and logging errors in Is there anything we can address? Shall I squash the older WIP commits or leave them there? If nothing else, shall we mention this feature in release notes or docs? |
The failing test seems to be unrelated as it failed to check out the "PR merge commit", maybe this is an issue with the git plugin like the one described here ? |
@asfaltboy Failing tests are related with force-push you don't need to worry about them. It is a new feature so documentation ( |
Thanks @felixxm, I doc'd the method in I feel, however, that this may be "too low-level" for the tools docs. |
a56357c
to
56e84d2
Compare
@asfaltboy I moved extra tests to a separate PR #11936. |
56e84d2
to
f98d2ec
Compare
@asfaltboy Thanks for updates 👍 I rebased from master, squashed commits. removed the |
debug() should bubbled up exceptions if occurring in test, but behave the same as run() when no exceptions occurred.
f98d2ec
to
1711c50
Compare
https://code.djangoproject.com/ticket/27391
Users calling debug() expect it to bubble up an exception if occurring in test, but behave the
same as run() when no exception occurred.