https://pantsbuild.org/ logo
#general
Title
# general
p

proud-dentist-22844

05/18/2021, 6:49 PM
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

enough-analyst-54434

05/18/2021, 6:56 PM
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

proud-dentist-22844

05/18/2021, 7:11 PM
I can see the output in the pycharm console, but pycharm's debugger never activates - it acts like there was no breakpoint.
h

happy-kitchen-89482

05/18/2021, 7:16 PM
Are you running in remote debugging mode?
Sounds like yes, but just double-checking
p

proud-dentist-22844

05/18/2021, 7:23 PM
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

happy-kitchen-89482

05/18/2021, 7:25 PM
Hmmm, weird
this works for me 100% of the time. Let me think.
p

proud-dentist-22844

05/18/2021, 7:25 PM
Maybe I don't have the file mappings setup right?
Hmm. Could it be because I'm using python 3.6?
h

happy-kitchen-89482

05/18/2021, 7:26 PM
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

proud-dentist-22844

05/18/2021, 7:28 PM
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

happy-kitchen-89482

05/18/2021, 7:38 PM
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

proud-dentist-22844

05/18/2021, 7:42 PM
yup.
I modified the monkey_patch code to activate the debugger first... now to get to where I actually wanted the breakpoint.
h

happy-kitchen-89482

05/18/2021, 7:50 PM
Grrrrrr, good to know that's a thing
p

proud-dentist-22844

05/18/2021, 8:11 PM
aargh. I hate it when code is failing outside the debugger, but works just fine when debugging...
h

happy-kitchen-89482

05/18/2021, 11:49 PM
The debugger collapses the wave function...
🤣 2
p

proud-dentist-22844

05/20/2021, 8:54 AM
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

happy-kitchen-89482

05/20/2021, 5:01 PM
I feel your anguish, those are the worst bugs
3 Views