How can I get the pycharm debugger hooked up to my...
# general
How can I get the pycharm debugger hooked up to my pytest run (running via
./pants test --debug
)? I followed the tip here: And I see that it connects to pycharm, and stdout is getting forwarded, but I'm unable to step through the code.
Do I need ? I don't see anything that supports pycharm 2021.1.1
No - not related. @proud-dentist-22844 can you say more about "but I'm unable to step through the code.". Does that mean you hang when trying to step, the IDE errors, or - what exactly happens? @happy-kitchen-89482 you wrote the pycharm bit IIRC - are there any caveats like --no-pantsd?
I can see the output in the pycharm console, but pycharm's debugger never activates - it acts like there was no breakpoint.
Are you running in remote debugging mode?
Sounds like yes, but just double-checking
I setup a pycharm "Python Debug Server", added pydevd-pycharm as a requirement, and imported + set_trace. => it connects to the debug window just fine.
I just tried with
but same thing.
Hmmm, weird
this works for me 100% of the time. Let me think.
Maybe I don't have the file mappings setup right?
Hmm. Could it be because I'm using python 3.6?
if you have
Copy code
import pydevd_pycharm
pydevd_pycharm.settrace('localhost', port=5000, stdoutToServer=True, stderrToServer=True)
in your code and that breakpoint is hit, then the code should halt there even if pycharm isn't connecting
I don't think the python version should affect anything, but who knows...
So if your code is acting as if the breakpoint isn't there, I wonder if it is actually being executed
what happens if you add print statements before and after the settrace?
It is executing because if I add a print statement after the settrace, then that print shows up in the pycharm console.
I put the settrace in a
method on a
class... maybe that has something to do with it?
I'm trying to get down into the guts of mongoengine / pymongo because their debug logs aren't telling me why it's hanging on connect. Thus, I'm trying to hook up a debugger.
hmm. Maybe it's fighting with eventlet...
so the print shows up in the console, meaning the settrace() executed, but the breakpoint doesn't actually break. That is odd.
Did you check "Suspend after connect" in the debug config?
I modified the monkey_patch code to activate the debugger first... now to get to where I actually wanted the breakpoint.
Grrrrrr, good to know that's a thing
aargh. I hate it when code is failing outside the debugger, but works just fine when debugging...
The debugger collapses the wave function...
🤣 2
FOUND IT! Previously nosetest was the test runner for these tests. Pytest imports things in a slightly different order (and pants does each file separately) so the eventlet monkey_patching wasn't happening before mongoengine was imported. Thus it totally hung. Now I have to figure out where to put this monkey_patching.
I really hope that once pants is in place, it will be easier to strip out eventlet... What a pain.
I feel your anguish, those are the worst bugs