How can I get the pycharm debugger hooked up to my...
# general
p
How can I get the pycharm debugger hooked up to my pytest run (running via
./pants test --debug
)? I followed the tip here: https://www.pantsbuild.org/v2.5/docs/python-test-goal#running-tests-interactively 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 https://plugins.jetbrains.com/plugin/7412-pants-support/versions/bleedingedge ? I don't see anything that supports pycharm 2021.1.1
e
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?
p
I can see the output in the pycharm console, but pycharm's debugger never activates - it acts like there was no breakpoint.
h
Are you running in remote debugging mode?
Sounds like yes, but just double-checking
p
yeah
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
--no-pantsd
but same thing.
h
Hmmm, weird
this works for me 100% of the time. Let me think.
p
Maybe I don't have the file mappings setup right?
Hmm. Could it be because I'm using python 3.6?
h
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?
p
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
setUpClass
method on a
unittest2.TestCase
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...
h
Gotcha
hmmmm
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?
p
yup.
I modified the monkey_patch code to activate the debugger first... now to get to where I actually wanted the breakpoint.
h
Grrrrrr, good to know that's a thing
p
aargh. I hate it when code is failing outside the debugger, but works just fine when debugging...
h
The debugger collapses the wave function...
🤣 2
p
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.
h
I feel your anguish, those are the worst bugs