Skip to content

Conversation

@blueyed
Copy link
Contributor

@blueyed blueyed commented Nov 18, 2018

This handles header similar to Python 3.7 does it, and forwards any
other keyword arguments to the Pdb constructor.

This allows for __import__("pdb").set_trace(skip=["foo.*"]).

Fixes #4416.

This handles `header` similar to Python 3.7 does it, and forwards any
other keyword arguments to the Pdb constructor.

This allows for `__import__("pdb").set_trace(skip=["foo.*"])`.

Fixes pytest-dev#4416.
@codecov
Copy link

codecov bot commented Nov 19, 2018

Codecov Report

Merging #4419 into features will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@             Coverage Diff             @@
##           features   #4419      +/-   ##
===========================================
+ Coverage     95.88%   95.9%   +0.01%     
===========================================
  Files           111     111              
  Lines         24997   25545     +548     
  Branches       2442    2537      +95     
===========================================
+ Hits          23969   24498     +529     
- Misses          726     742      +16     
- Partials        302     305       +3
Flag Coverage Δ
#docs 30.05% <3.84%> (+0.22%) ⬆️
#doctesting 30.05% <3.84%> (+0.22%) ⬆️
#linting 30.05% <3.84%> (+0.22%) ⬆️
#linux 95.74% <100%> (+0.02%) ⬆️
#nobyte 92.63% <15.38%> (+0.28%) ⬆️
#numpy 92.22% <100%> (-0.92%) ⬇️
#pexpect 41.81% <100%> (+0.04%) ⬆️
#py27 94.05% <100%> (+0.02%) ⬆️
#py34 92.14% <15.38%> (+0.04%) ⬆️
#py35 92.16% <15.38%> (+0.04%) ⬆️
#py36 92.18% <15.38%> (+0.04%) ⬆️
#py37 94.1% <100%> (+0.01%) ⬆️
#trial 92.22% <100%> (-0.92%) ⬇️
#windows 94.1% <38.46%> (-0.01%) ⬇️
#xdist 93.89% <38.46%> (-0.04%) ⬇️
Impacted Files Coverage Δ
testing/test_pdb.py 99.05% <100%> (+0.03%) ⬆️
src/_pytest/debugging.py 84.45% <100%> (+0.43%) ⬆️
testing/test_collection.py 97.02% <0%> (-2.77%) ⬇️
src/_pytest/python.py 95.3% <0%> (+0.02%) ⬆️
src/_pytest/assertion/rewrite.py 95.93% <0%> (+0.23%) ⬆️
src/_pytest/config/__init__.py 95.44% <0%> (+0.43%) ⬆️
src/_pytest/terminal.py 93.02% <0%> (+0.85%) ⬆️
testing/test_session.py 98.52% <0%> (+2.01%) ⬆️
src/_pytest/pytester.py 89.74% <0%> (+2.33%) ⬆️
testing/test_assertrewrite.py 86.23% <0%> (+2.85%) ⬆️

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 62967b3...92a2884. Read the comment docs.

It handles ``header`` similar to Python 3.7 does it, and forwards any
other keyword arguments to the ``Pdb`` constructor.

This allows for ``__import__("pdb").set_trace(skip=["foo.*"])``.
Copy link
Member

Choose a reason for hiding this comment

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

this changes the signature of pdb.set_trace() I don't think we should do this (we also have to manually adjust our code every time cpython adds a parameter to this function which seems non-ideal)

Copy link
Member

Choose a reason for hiding this comment

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

the changelog text is incorrect, it should talk about pytest.set_trace

Copy link
Member

Choose a reason for hiding this comment

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

pytest monkeypatches pdb.set_trace:

import pdb
import pytest


def test():
    assert pdb.set_trace.__module__ == '_pytest.debugging'
$ pytest t.py -q
.                                                                        [100%]
1 passed in 0.00 seconds

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #4416 (comment).

We're not changing the signature, but just pass through args and kwargs.
pdb.set_trace looks like it might never handle args (*, header=None in py37), but just in case and/or if you want to hack something into this yourself.
This PR handles header added in py37, but in general (through the terminal writer), and forwards anything else to Pdb.__init__.
pdb++ makes use of this, and any custom pdbcls could do so then.

I do not see a compatibility issue really, but it makes it just a bit more forward-compatible - also a new kwarg (like "header") might cause an error then when Pdb.__init__ does not handle it.

For this, we could try it with **kwargs first, and then without them on TypeError, logging a warning.

Copy link
Contributor

Choose a reason for hiding this comment

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

@asottile right now, there is not a good way to provide those arguments to Pdb directly. If you could read into the original request #4416, I think it could help to give a better understanding on the context of the change.

Right now we are constrained to build the Pdb class in the predefined way, with no arguments. However with this patch we would be able to initalize Pdb, or any other implementation (I am keen on TerminalPdb from ipython, or pycharm's pdb class) with the custom arguments to support debugging asyncio.

I would highly encourage to try debugging asyncio code with pytest.set_trace() with no skip support, and you will find that all the control changes from the ioloop and back are almost impossible to follow due to all the await syntax.

This will ease a lot my development of fully asyncio libraries/applications, as many times you find bugs through pytest, and you need to debug them in that specific fixtured environment.

Copy link
Member

Choose a reason for hiding this comment

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

Any news on this folks? @asottile do you still strongly object to this?

Copy link
Member

Choose a reason for hiding this comment

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

Would help to get @RonnyPfannschmidt's opinion on this as well.

Copy link
Member

Choose a reason for hiding this comment

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

I'd put myself at non blocking opposed go ahead!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Heh, I can see @RonnyPfannschmidt literally on some fence already.. ;)

I'm also a bit on @asottile's side here in general, but do not really see a good way around this. Maybe we could use inspect to have expected/proper TypeErrors?

Also, this removes the break kwarg that could previously have been used to do pdb.set_trace(break=False) - although it appears to come only from internal use without refactoring it properly (54d3cd5), i.e. an API break as it stands now.

Copy link
Member

Choose a reason for hiding this comment

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

I think the thing that convinces me that this is alright is that an interactive call, so the user knows he is running its own debugger tracing function. If this was an API call I would also be against it, as you don't know what debugger the person using your API is.

But let's see @RonnyPfannschmidt's opinion, if he is also against this as @asottile is, then I'm afraid we will need to close this PR.

def test_1():
i = 0
print("hello17")
pytest.set_trace(header="== my_header ==")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asottile
This currently fails, i.e. we do not support py37's signature.

It handles ``header`` similar to Python 3.7 does it, and forwards any
other keyword arguments to the ``Pdb`` constructor.

This allows for ``__import__("pdb").set_trace(skip=["foo.*"])``.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See #4416 (comment).

We're not changing the signature, but just pass through args and kwargs.
pdb.set_trace looks like it might never handle args (*, header=None in py37), but just in case and/or if you want to hack something into this yourself.
This PR handles header added in py37, but in general (through the terminal writer), and forwards anything else to Pdb.__init__.
pdb++ makes use of this, and any custom pdbcls could do so then.

I do not see a compatibility issue really, but it makes it just a bit more forward-compatible - also a new kwarg (like "header") might cause an error then when Pdb.__init__ does not handle it.

For this, we could try it with **kwargs first, and then without them on TypeError, logging a warning.

@blueyed blueyed merged commit 8152b68 into pytest-dev:features Dec 11, 2018
@blueyed blueyed deleted the set_trace-kwargs branch December 11, 2018 03:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants