Skip to content

pdb: add option to skip pdb.set_trace()#4854

Merged
blueyed merged 1 commit into
pytest-dev:featuresfrom
blueyed:pdb-skip
Apr 3, 2019
Merged

pdb: add option to skip pdb.set_trace()#4854
blueyed merged 1 commit into
pytest-dev:featuresfrom
blueyed:pdb-skip

Conversation

@blueyed

@blueyed blueyed commented Feb 28, 2019

Copy link
Copy Markdown
Contributor

TODO:

  • doc ?
  • better name(s) ?

@blueyed blueyed added type: enhancement new feature or API change, should be merged into features branch plugin: debugging related to the debugging builtin plugin labels Feb 28, 2019
@blueyed

blueyed commented Feb 28, 2019

Copy link
Copy Markdown
Contributor Author

It is meant ease running tests, where the code is (full of) __import__("pdb").set_trace().

@codecov

codecov Bot commented Feb 28, 2019

Copy link
Copy Markdown

Codecov Report

Merging #4854 into features will increase coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff              @@
##           features    #4854      +/-   ##
============================================
+ Coverage     96.05%   96.06%   +<.01%     
============================================
  Files           114      114              
  Lines         25737    25747      +10     
  Branches       2547     2549       +2     
============================================
+ Hits          24722    24734      +12     
+ Misses          704      703       -1     
+ Partials        311      310       -1
Impacted Files Coverage Δ
testing/test_pdb.py 99.18% <100%> (+0.01%) ⬆️
src/_pytest/debugging.py 89.07% <100%> (+0.24%) ⬆️
testing/acceptance_test.py 98.03% <0%> (+0.39%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b5cddc...adebfd0. Read the comment docs.

@blueyed blueyed requested a review from jeffreyrack March 1, 2019 08:26
@blueyed blueyed changed the title pdb: add option to skip pdb.set_trace() [RFC] pdb: add option to skip pdb.set_trace() Mar 1, 2019

@jeffreyrack jeffreyrack left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to wrap pdb.set_trace() when the option isn't used to help users know about the option?

Something like:

example_test.py
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> PDB set_trace (IO-capturing turned off) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
To disable break points set via pdb, use --pdb-skip.
> /home/vagrant/pytest-source/example_test.py(7)test_a()
-> a = 'b'
(Pdb)

Comment thread src/_pytest/debugging.py
@blueyed

blueyed commented Mar 1, 2019

Copy link
Copy Markdown
Contributor Author

What about the option name(s)?

I've used/added a longer run for clarify, but the typical use would rather be to append -skip to an existing --pdb (the short version).
Since there is --pdbcls it should maybe be --pdbskip instead?!

@nicoddemus

Copy link
Copy Markdown
Member

Since there is --pdbcls it should maybe be --pdbskip instead?!

Personally I prefer --pdb-skip, but I'm fine either way. 👍

@blueyed

blueyed commented Mar 2, 2019

Copy link
Copy Markdown
Contributor Author

@jeffreyrack

To disable break points set via pdb, use --pdb-skip.

Not a bad idea - but in general it just adds noise - typically you would a set_trace to trigger.

I consider this new feature rather as a gem for advanced users, which are also messy by needing it in the first place.. ;)

Similar to how e.g. pdbpp also has an edit command to edit the source in-place, but does not add a note about it when entering interactive mode - but maybe it could/should? :p

@blueyed

blueyed commented Mar 2, 2019

Copy link
Copy Markdown
Contributor Author

@nicoddemus
I've added a method to pass stdin to MultiCapture, which can be used to interact with pdb in tests.
What do you think?

@nicoddemus

Copy link
Copy Markdown
Member

I've added a method to pass stdin to MultiCapture, which can be used to interact with pdb in tests.

The code looks good, but I'm not sure I understand the user case, can you please elaborate?

@blueyed

blueyed commented Mar 3, 2019

Copy link
Copy Markdown
Contributor Author

The code looks good, but I'm not sure I understand the user case, can you please elaborate?

It allows to use inprocess pytest instead of pexpect.
Extended the example a bit.

One downside currently is that you do not get the "stdin gets echoed to stdout" that terminals normally do.

@blueyed blueyed changed the title [RFC] pdb: add option to skip pdb.set_trace() [WIP] pdb: add option to skip pdb.set_trace() Mar 3, 2019
@blueyed

blueyed commented Mar 4, 2019

Copy link
Copy Markdown
Contributor Author

Waiting for coverage improvements through master to rebase this against.

@asottile

asottile commented Mar 5, 2019

Copy link
Copy Markdown
Member

Would it be better to not implement this and wait for PYTHONBREAKPOINT=0 to become ubiquitous

@blueyed

blueyed commented Mar 5, 2019

Copy link
Copy Markdown
Contributor Author

Would it be better to not implement this and wait for PYTHONBREAKPOINT=0 to become ubiquitous

Oh, wasn't aware of it.

Should we just respect / look at it here instead?

@asottile

asottile commented Mar 5, 2019

Copy link
Copy Markdown
Member

Would it be better to not implement this and wait for PYTHONBREAKPOINT=0 to become ubiquitous

Oh, wasn't aware of it.

Should we just respect / look at it here instead?

👍 sg2m

@blueyed

blueyed commented Mar 5, 2019

Copy link
Copy Markdown
Contributor Author

Well, almost finished it - but then thought that having to set PYTHONBREAKPOINT=0 is much more involving than just appending --pdb-skip (which also can be completed through your shell).
I therefore think we should have both.

@asottile

asottile commented Mar 5, 2019

Copy link
Copy Markdown
Member

My leaning is that pytest shouldn't reimplement stuff that's standard python (then you have to learn two sets of tools), curious to hear what the others have to say though

@blueyed

blueyed commented Mar 5, 2019

Copy link
Copy Markdown
Contributor Author

Well, PYTHONBREAKPOINT is only supported with breakpoint() - given that we should probably not look at it at all with pdb.set_trace.

@asottile

asottile commented Mar 5, 2019

Copy link
Copy Markdown
Member

That's a good point, which makes this feature seem even less of a good idea since it won't handle other debuggers like pudb / ipdb / the dozen others

@blueyed

blueyed commented Mar 5, 2019

Copy link
Copy Markdown
Contributor Author

Yes, it is specific to pdb, but that's implied through the name already.
pytest only monkeypatches pdb.set_trace, not more. Since I am using pdbpp this is fine, since it monkeypatches pdb itself, but AFAIK there are plugins for ipdb etc to make pytest work with them. That sounds like a situation to be improved in general though (not related to this PR currently).

@asottile

asottile commented Mar 5, 2019

Copy link
Copy Markdown
Member

My hope for the debugging plugins was that as we eventually drop <3.7 we can just use breakpoint and not need all these options and plugins

@blueyed

blueyed commented Mar 17, 2019

Copy link
Copy Markdown
Contributor Author

Will move the stdin improvements (e2cd884) to #4937 / a new PR.

@blueyed blueyed changed the title [WIP] pdb: add option to skip pdb.set_trace() pdb: add option to skip pdb.set_trace() Apr 2, 2019
@blueyed

blueyed commented Apr 2, 2019

Copy link
Copy Markdown
Contributor Author

Just found that --pdbcls unittest.mock:Mock can be used already for skipping set_trace, except for that it would still print "PDB set_trace (IO-capturing turned off)", and obviously also breaks --pdb.
But maybe proving a better no-op-for-set_trace class is a good idea?

Otherwise I think this is good for now, but could only need some addition to the docs maybe?

@blueyed blueyed merged commit e88aa95 into pytest-dev:features Apr 3, 2019
@blueyed blueyed deleted the pdb-skip branch April 3, 2019 20:25
@asottile

asottile commented Apr 3, 2019

Copy link
Copy Markdown
Member

:S

@blueyed

blueyed commented Apr 3, 2019

Copy link
Copy Markdown
Contributor Author

?

@asottile

asottile commented Apr 3, 2019

Copy link
Copy Markdown
Member

@blueyed

blueyed commented Apr 3, 2019

Copy link
Copy Markdown
Contributor Author

@asottile
I see - but this is another case for a review that has been approved (hit my search for that as a single result), and then getting not feedback via my last comments.
I've came back to this due to having a need for it mysel, but hoped for "hopefully we're not having to deprecate anything later" when merging it.

@blueyed

blueyed commented Apr 3, 2019

Copy link
Copy Markdown
Contributor Author

As for looking at PYTHONBREAKPOINT: I think that this is not really that much relevant here, since this is about skipping pdb.set_trace() alone, but certainly something good to consider in a future PR - I'd be happy to review something in this regard from you, after all I've noticed you getting the improved "Quitting debugger" outcome during the screencast that I've watched.. :)

@asottile

asottile commented Apr 3, 2019

Copy link
Copy Markdown
Member

@asottile
I see - but this is another case for a review that has been approved (hit my search for that as a single result), and then getting not feedback via my last comments.
I've came back to this due to having a need for it mysel, but hoped for "hopefully we're not having to deprecate anything later" when merging it.

heh well I didn't think I had to block it because it was [WIP] when I looked at it -- usually when moving something from WIP -> not WIP you get another review

@blueyed

blueyed commented Apr 3, 2019

Copy link
Copy Markdown
Contributor Author

usually when moving something from WIP -> not WIP you get another review

Not here.. WIP is just a silly blocking status.

@asottile

asottile commented Apr 3, 2019

Copy link
Copy Markdown
Member

after all I've noticed you getting the improved "Quitting debugger" outcome during the screencast that I've watched.. :)

have greatly appreciated this btw 👍 I used to ^\ pytest but not any more!

@blueyed

blueyed commented Apr 4, 2019

Copy link
Copy Markdown
Contributor Author

@asottile

I used to ^\ pytest but not any more!

Interesting - did not know that exists..

blueyed added a commit to blueyed/pytest that referenced this pull request Apr 27, 2019
This reverts commit e88aa95, reversing
changes made to 1410d3d.

I do not think it warrants an option anymore, and there is a way to
achieve this via `--pdbcls` if needed.
@blueyed

blueyed commented Apr 27, 2019

Copy link
Copy Markdown
Contributor Author

Reverting it in #5173.

asottile added a commit that referenced this pull request Apr 27, 2019
Revert "Merge pull request #4854 from blueyed/pdb-skip"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugin: debugging related to the debugging builtin plugin type: enhancement new feature or API change, should be merged into features branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants