-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-42722: Add --debug command line option to unittest to enable post-mortem debugging #23900
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
base: main
Are you sure you want to change the base?
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.
Please add a news entry.
def test_debug(self): | ||
program = self.program | ||
program.testRunner = FakeRunner | ||
program.parseArgs([None, '--debug']) | ||
self.assertTrue(program.debug) |
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 believe more tests are needed.
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.
Do you mean more tests for the argument parsing part? I've also added a general test that ensures that any exception is leaked for --debug
rather than being consumed by unittest.
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.
@ZackerySpytz What kind of tests do you think should be added? I'm happy to add more, but at the moment it's not clear to me what exactly should be tested in addition to what's already there.
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.
Never mind.
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.
@ZackerySpytz I'm not familiar with the review process, what do I need to do to further advance this PR?
Co-authored-by: Zackery Spytz <zspytz@gmail.com>
This PR is stale because it has been open for 30 days with no activity. |
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 checked out this branch, fresh compile, ran:
cpython on resolve-42722 [$?] via 🐍 v3.11.0a3+>
./python -m unittest --debug ../TestGeneric/main.py
and
./python --debug ../TestGeneric/main.py
but all I got was
module = __import__(module_name) ValueError: Empty module name
and
unknown option --debug usage: ./python [option] ... [-c cmd | -m mod | file | -] [arg] ... Try python -h for more information.
Where main.py is the test script from the bug.
Any ideas why or what I am doing wrong?
How did you compile exactly? To use the latest version, you'd have to check out this branch locally, then merge back the main dev branch and then build it.
When you invoke it like that, you're passing
What bug are you referring to? You mean the BPO issue? |
On Github on my cpython fork: Fetch Upstream (and merge). Pull my fork to local with Github GUI. OK so I tried again with the last param as --debug and the output is: Finally, yes the bpo. |
Yes, I can confirm that, so it looks like it works: it's calling
|
I used this and a problem was that skipped tests broke the behavior with early crashes at --- a/Lib/unittest/case.py
+++ b/Lib/unittest/case.py
@@ -653,9 +653,19 @@ def __call__(self, *args, **kwds):
def debug(self):
"""Run the test without collecting errors in a TestResult"""
- self.setUp()
- getattr(self, self._testMethodName)()
- self.tearDown()
+ print(self, "...", end=' ', file=sys.stderr)
+ try:
+ self.setUp()
+ except SkipTest:
+ print("SKIPPED", file=sys.stderr)
+ else:
+ try:
+ getattr(self, self._testMethodName)()
+ except SkipTest:
+ print("SKIPPED", file=sys.stderr)
+ else:
+ print("ok", file=sys.stderr)
+ self.tearDown()
while self._cleanups:
function, args, kwargs = self._cleanups.pop(-1)
function(*args, **kwargs)
I'd also like to see the usual (verbose) progress and (in success case) final summary info, particularly on long test runs and with complex custom test loaders, so that this mode is usable as the primary mode in the first place during dev instead of the "dead" display only mode. Thus the regular result collection business in debug mode. Instead of void silence till end. After all a debug / crash mode is of fundamental importance. Wonder why such thing is still not in. |
This comment was marked as spam.
This comment was marked as spam.
The following commit authors need to sign the Contributor License Agreement: |
https://bugs.python.org/issue42722