1

I saw this question: Can I debug with python debugger when using py.test somehow? but it doesn't really help, because I need to debug hooks, some of them not written by me, where modifying the code of the hook is really cumbersome.

Also, pytest runs through pipenv run. It's already difficult to make them both work together. I couldn't so far find a combination of pdb, pipenv and pytest that would launch each other.


Another way I could do it is by calling pytest.main() from my code, however, this means that other people who want to run my tests will have to use this "trampoline" to run other tests. I can live with this, but it still feels like it shouldn't be necessary.

georgexsh
  • 15,984
  • 2
  • 37
  • 62
wvxvw
  • 8,089
  • 10
  • 32
  • 61
  • what is `pipenv exec`? not mentioned in its doc. – georgexsh Jan 10 '18 at 16:32
  • @georgexsh sorry, that's `pipenv run`, confused with some similar tool, maybe `bundler` or some such. I'll fix the question. – wvxvw Jan 11 '18 at 06:38
  • why can't you use breakpoints in pdb? – georgexsh Jan 11 '18 at 07:38
  • @georgexsh Because I'd need to get root, edit files in `/usr/lib/pythonX/site-packages`? Or, even worse, trying to discover where `pipenv` installed `pytest` and its plugins... That's just too much trouble for development process. – wvxvw Jan 11 '18 at 07:51
  • but you could control test case file, right? launch pdb within the test case, set a breakpoint at the line in the hook you interested, then continue, pdb will break later. – georgexsh Jan 12 '18 at 10:46
  • @georgexsh wel... that's too late of course. In my more specific case, I wanted to see how some plugin parsed / added command-line arguments. – wvxvw Jan 12 '18 at 14:27

1 Answers1

0

I guess this is what you need, invoke pdb as early as possible:

`pipenv --py` -c 'import pdb, pytest; pdb.set_trace(); pytest.main()'
georgexsh
  • 15,984
  • 2
  • 37
  • 62
  • Interesting. I'll have to try this Sunday. – wvxvw Jan 12 '18 at 23:12
  • Sorry, I ended up adding a `__main__.py` file which fixed it for a time being, but then I ran into a host of problems with `pipenv` on Windows... at the moment, I'm not sure I'm going to use `pipenv` at all. – wvxvw Jan 15 '18 at 08:48