Debugging pytest post mortem exceptions in pycharm/pydev
Asked Answered
C

1

11

I would like to use the built in Pytest runner of PyCharm together with the debugger without pre-configuring breakpoints.

The problem is that exceptions in my test are caught by Pytest so PyCharm's post mortem debugger cannot handle the exception.

I know using a breakpoint works but I would prefer not to run my test twice.

Found a way to do this in Unittest, I would like to know if something like this exists in Pytest.

Is there a way to catch unittest exceptions with PyCharm?

Colter answered 29/12, 2012 at 21:24 Comment(1)
This question is similar to: Can PyCharm drop into debug when py.test tests fail. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.Blodgett
A
13

Are you using pytest-pycharm plugin? Looks like it works for me. Create virtualenv, pip install pytest pytest-pycharm, use this virtualenv at PyCharm Edit configuration -> Python Interpreter and then run with Debug ... Example:

import pytest

def test_me():
    assert None

if __name__ == '__main__':
    pytest.main(args=[__file__])

PyCharm debugger stops at assert None point, with (<class '_pytest.assertion.reinterpret.AssertionError'>, AssertionError(u'assert None',), None)

EDIT

Set Preferences > Tools > Python Integration Tools > Default test runner to py.test. Then Run > Debug 'py.test in test_me.py'

Assessment answered 3/9, 2014 at 10:31 Comment(2)
It helped me! Thank you !Restless
See this answer on how to make the debug console work with this!Yoheaveho

© 2022 - 2024 — McMap. All rights reserved.