Skip to content
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

Breakpoints with nosetests and pdb/ipdb #5907

Closed
jluttine opened this issue Apr 27, 2016 · 12 comments
Closed

Breakpoints with nosetests and pdb/ipdb #5907

jluttine opened this issue Apr 27, 2016 · 12 comments

Comments

@jluttine
Copy link
Contributor

In Python mode, one can run nosetests with pdb by using nosetests-pdb-* (SPC t). This works nicely. The default way of setting breakpoints is with python-toggle-breakpoint (SPC d b). However, these breakpoints don't work with nosetests. The default breakpoint is:

import pdb; pdb.set_trace()

(See https://github.com/syl20bnr/spacemacs/blob/develop/layers/+lang/python/funcs.el#L24). Having these in the code just freezes nose. With nose, one needs to use:

import nose.tools; nose.tools.set_trace()

I'm not an expert here, so probably someone who knows better should comment. But I suppose the first breakpoint style works when executing code normally. The second style works when running unit tests with nose. If this is the case, perhaps we'd need to add a separate breakpoint toggle for (nose)tests? Something like python-toggle-nose-breakpoint under SPC d or SPC t?

Or should this whole matter be discussed in https://github.com/syl20bnr/nose.el?

If we'd add a toggle for the latter breakpoint, perhaps the command should be modified a bit so it wouldn't conflict with possible other nose named variables/methods? For instance, import nose.tools as nosepdb; nosepdb.set_trace() (which would match the current breakpoint highlighting regexp).

Any comments? I can try to make a pull request, but I'd like to hear some comments and ideas.

@jluttine
Copy link
Contributor Author

Ideally, it'd be great if one line would work for both cases. For instance, if there's a variable which can be checked if nosetests are running, then we could use an if-else based breakpoint line. Not sure if it is possible (i.e., is there a variable which tells whether running under nose or not?).

@cpaulik
Copy link
Contributor

cpaulik commented Apr 27, 2016

I don't have a nose project to test this but probably adding the -s flag should make normal pdb breakpoints work.

So please try adding -s here and see if that works.

@jluttine
Copy link
Contributor Author

@cpaulik Yep, that fixes it. And actually, probably things work by default. I have explicitly disabled -s flag by setting nose-capture to t. Setting it to nil fixes this. But still I'm thinking would be a good idea to support nose capturing stdout and still be able to use pdb.

Also, now I'm studying how I could get ipdb to work. Similar problems but doesn't work yet. It should be better than pdb.

@jluttine
Copy link
Contributor Author

jluttine commented Apr 27, 2016

This is weird. If I use

import ipdb; ipdb.set_trace()

breakpoints, the debugger window doesn't show outputs. I can write commands and they seem to "work" although nothing shows up. That is, I can use exit to exit and the process dies. It works if I replace ipdb with pdb. I have no idea whether this is a bug in ipdb, nose, nose.el or somewhere else.

EDIT: ipdb works when ran with nosetests from the terminal without Emacs.

EDIT: Probably an issue in GUD: http://stackoverflow.com/a/31232014

EDIT: Might work with realgud: realgud/realgud#71

@jluttine jluttine changed the title Breakpoints with nosetests and pdb Breakpoints with nosetests and pdb/ipdb Apr 27, 2016
@cpaulik
Copy link
Contributor

cpaulik commented Apr 28, 2016

My guess would be that the issue is with nose or nose.el since ipdb breakpoints work with py.test.

@jluttine
Copy link
Contributor Author

@cpaulik Are you using the default gud or realgud or something else as the debugger front-end? I understood that gud doesn't support ipdb so I'd be surprised to hear if ipdb worked with gud if using py.test. But that'd be good to know.

@cpaulik
Copy link
Contributor

cpaulik commented Apr 28, 2016

I'm using out of the box spacemacs. No special debugger backend.

Just to make sure that I don't miss any features. By working I mean the following:

  • I set a breakpoint in the python code import ipdb; ipdb.set_trace()
  • Run a python test using e.g. SPC m t T
  • The code window follows the debugger window.

@jluttine
Copy link
Contributor Author

@cpaulik Btw, are you using ipdb debugger? Do you know, how I could enable it for Spacemacs? I installed ipdb python package but it seems that Spacemacs still uses pdb with pytest.

@cpaulik
Copy link
Contributor

cpaulik commented Oct 13, 2016

@jluttine Do you mean that pytest uses pdb on failure even when ipdb is installed? If so then that is expected since py.test does not support ipdb out of the box. There is/was https://github.com/mverteuil/pytest-ipdb which could be installed to enable a --ipdb command option for pytest but this is not supported by py.test.el.

But it should work when you set a breakpoint manually using SPC m d b

@jluttine
Copy link
Contributor Author

Ok, thanks for the info!

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
@lebensterben lebensterben removed the stale marked as a stale issue/pr (usually by a bot) label Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants