Skip to content

enter debugger when warning is raised #3223

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

Closed
twmr opened this issue Feb 14, 2018 · 12 comments
Closed

enter debugger when warning is raised #3223

twmr opened this issue Feb 14, 2018 · 12 comments
Labels
plugin: warnings related to the warnings builtin plugin type: question general question, might be closed after 2 weeks of inactivity

Comments

@twmr
Copy link
Contributor

twmr commented Feb 14, 2018

Is it possible to enter the debugger when a warning is raised similar to the usage of the --pdb flag when normal exceptions are raised?

The reason why I'm asking is that I have the following warning in the warnings summary and I wan't to know where and why it is raised:

=============================== warnings summary ===============================
integrationtests/test_blocks.py::TestA::test_a
  /usr/lib64/python2.7/site-packages/numpy/core/_methods.py:83: RuntimeWarning: Degrees of freedom <= 0 for slice
    warnings.warn("Degrees of freedom <= 0 for slice", RuntimeWarning)
@twmr twmr added the type: question general question, might be closed after 2 weeks of inactivity label Feb 14, 2018
@pytestbot pytestbot added the plugin: warnings related to the warnings builtin plugin label Feb 14, 2018
@twmr twmr changed the title enter debug when warning is raised enter debugger when warning is raised Feb 14, 2018
@twmr
Copy link
Contributor Author

twmr commented Feb 14, 2018

-W error turns warnings into erros and is a cpython paramter. However if I pass it to pytest using python -W error -m pytest I get the following exception:

  File "/usr/lib/python2.7/site-packages/_pytest/fixtures.py", line 834, in FixtureFunctionMarker
    params = attr.ib(convert=attr.converters.optional(tuple))
  File "/usr/lib/python2.7/site-packages/attr/_make.py", line 153, in attrib
    DeprecationWarning, stacklevel=2
DeprecationWarning: The `convert` argument is deprecated in favor of `converter`.  It will be removed after 2019/01.

@blueyed
Copy link
Contributor

blueyed commented Feb 14, 2018

The exception with python -W error -m pytest seems to be good/expected, no?
And you can see where it is coming from there (pytest itself causes it apparently).

Does python -W error -m pytest --pdb give you a pdb prompt then?

@twmr
Copy link
Contributor Author

twmr commented Feb 14, 2018

No this exception is not expected, since it is raised before the tests are executed. Here is the full traceback:

Traceback (most recent call last):
  File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/lib/python2.7/site-packages/pytest.py", line 13, in <module>
    from _pytest.fixtures import fixture, yield_fixture
  File "/usr/lib/python2.7/site-packages/_pytest/fixtures.py", line 832, in <module>
    class FixtureFunctionMarker(object):
  File "/usr/lib/python2.7/site-packages/_pytest/fixtures.py", line 834, in FixtureFunctionMarker
    params = attr.ib(convert=attr.converters.optional(tuple))
  File "/usr/lib/python2.7/site-packages/attr/_make.py", line 153, in attrib
    DeprecationWarning, stacklevel=2
DeprecationWarning: The `convert` argument is deprecated in favor of `converter`.  It will be removed after 2019/01.

@blueyed
Copy link
Contributor

blueyed commented Feb 14, 2018

Ah, it is another one - sorry for the confusion.
I wonder if it (using --pdb to get to yours) works after fixing the one in pytest (and any others).

@RonnyPfannschmidt
Copy link
Member

this is a pytest issue actually - we use a deprecated attrs api and should fix that bit

a more specific warning filter s (matching only numpy for errors) should help

@blueyed
Copy link
Contributor

blueyed commented Feb 15, 2018

@RonnyPfannschmidt
Yes, but the issue itself is about using --pdb to get to a warning (after pytest starts up after all).
@Thisch
Please try this after fixing the warning in pytest itself (and/or using -W with some filter to skip pytest's warning - not sure if that is possible).

@blueyed
Copy link
Contributor

blueyed commented Feb 15, 2018

Ah.. that's what Ronny meant likely: only match numpy's warning, and then use --pdb.
Please try that.

@twmr
Copy link
Contributor Author

twmr commented Feb 15, 2018

@RonnyPfannschmidt Everything works fine with attr-17.3.0, but some minor fixes to pytest are required for attr-17.4.0. (convert needs to be renamed to converter see https://github.com/python-attrs/attrs/blob/17.4.0/src/attr/_make.py#L59). How do we want to 'fix' this? Can we increase the minimal required attrs version (from 17.2.0 to 17.4.0) or should we add backwards compatibilty code for attrs<17.4?

@RonnyPfannschmidt
Copy link
Member

i propose updating the requirement and changing the call

twmr added a commit to twmr/pytest that referenced this issue Feb 15, 2018
@twmr
Copy link
Contributor Author

twmr commented Feb 16, 2018

I don't understand why the coveralls job failed.

@RonnyPfannschmidt
Copy link
Member

seems like a config issue, i believe merging is just fine

@twmr
Copy link
Contributor Author

twmr commented Feb 18, 2018

I've just discovered that there is already a -W option for pytest. This is great!! Therefore I don't have to start pytest with python -W error -m pytest --pdb but can write pytest -W error --pdb. I think we can close this issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugin: warnings related to the warnings builtin plugin type: question general question, might be closed after 2 weeks of inactivity
Projects
None yet
Development

No branches or pull requests

5 participants