-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
3610 add trace option #3647
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
3610 add trace option #3647
Conversation
src/_pytest/debugging.py
Outdated
@@ -38,6 +49,8 @@ def pytest_configure(config): | |||
else: | |||
pdb_cls = pdb.Pdb | |||
|
|||
global immediately_break | |||
immediately_break = config.getvalue("trace") |
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 should be a option to the pdbinvoke plugin, which then could handle the pyfunc_call
src/_pytest/debugging.py
Outdated
if pyfuncitem._isyieldedfunction(): | ||
pyfuncitem.args = [testfunction, pyfuncitem._args] | ||
else: | ||
if "func" in pyfuncitem._fixtureinfo.argnames: |
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 is already availiable in request - the fixture should be named pytest_test_function and be availiable in any case
a followup could be some docs |
Hi @jeffreyrack, thanks a lot for the PR. The option works well, each test starts tracing into PDB as advertised. But how do I quit the debugger?
I managed to quit by killing the terminal, but that doesn't seem like a good UI. Or perhaps I am missing something? |
@nicoddemus Quit/exit will quit the debugger, which will then get started again at the start of the next test. I believe that this is consistent with the --pdb option, where quitting the debugger will continue running the tests until the next time error that causes the debugger to be entered again. Do you have a recommendation on what might be a better a better UI that allows the user to exit entirely? |
Oh, I agree with you that it is consistent. And the feature does seem useful, my only concern is that might get some users by surprise because there's no obvious way to "stop" debugging (it certainly does not feel friendly when you run that in a file with a lot of tests, I tested with
Some ideas, just throwing them around:
All in all this seems like a really nice feature, just trying to make it a little more user friendly because that was my first impression when trying it out (or again I'm missing something more obvious than killing the terminal). |
(cc @brianmaissy which also contributed to |
re: hard to kill tests -- I've noticed the same thing when running with The other thing is |
FWIW uf we can't find a nice solution for now, I'm fine with merging this as is; the feature feels solid, and we can always improve it later. |
same here, all for merging this even as-is 👍 |
Merged then! Thanks a lot @jeffreyrack! 😁 |
Was it considered to use functools.partial here? |
that would require a extension of the calling mechanism, which is likely to generate way more pain (imho) |
@RonnyPfannschmidt ? |
@blueyed i did read this one before the actual solution and misunderstood the question |
Closes #3610 by adding the --trace option to pytest.
This option can be used to enter the debugger at the start of every test being ran.
Example usage:
While implementing this PR, there were a couple of things I wasn't sure how to best handle within the pytest codebase:
How to access a config value from within the pytest_pyfunc_call hook (Right now using a global variable, likely not the ideal way to implement).
Does it make sense to add the set_break option to PytestPdb.set_trace()? This doesn't seem like the right spot for it, and I'm instead thinking of moving the other logic out into another function which PytestPdb.set_trace calls before actually breaking.