spyder-unittest
spyder-unittest copied to clipboard
Can't run unittests in debug mode?
Description of your problem
I am not sure how to get the unittest runner to stop at set breakpoints. This is probably simple user error. Please guide me?
Please keep up the good work.
What steps will reproduce the problem?
- Set a breakpoint in a unit test or code the unit test exercises.
- Click "Run Tests"
What is the expected output? What do you see instead?
The execution should stop at the set breakpoints. Similar to the behaviour of Ctrl+F5 when attempting to execute a script from the IDE.
Key versions and other information:
Apologies for the patchy information. I highly suspect this is not a bug and I am missing something on the UI or the docs.
- Spyder version: 3.3.2
- Version of spyder-unittest plugin:
- Installation method for Spyder and the unittest plugin: Anaconda
- Python version: 3.6
- Testing framework used: py.test
- Testing framework version:
- Operating system: Windows 8.1
Any plans to address this issue? I am seeing the exact same issue.
This feature would be very useful.
In the meantime, here is a workaround.
Save the following code as, for instance, "main_pytest.py", and run it in Spyder. Not need to debug. The debugger will stop automatically on the pytest.main() line. Continue the execution to jump to your own breakpoints.
# Entry point for pytest
#
# This allows debugging of pytest unit tests in Spyder (or command line).
# In Spyder, set your breakpoints as required, then run this script
# (no need to debug, run is enough).
# The debugger will break automatically on the pytest.main() line.
# Continue the execution to jump to your own breakpoints.
import pdb
pdb.set_trace()
pytest.main()
Is there a workaround for unittest? The below does not find any test cases. Thank you. import unittest2 import pdb pdb.set_trace() unittest2.main()
I just gave it a try. What worked for me is to add the following lines to the test module you want to debug:
if __name__ == '__main__':
unittest.main()
And then start debugging the file.
In my test project, I cannot get spider-unittest to discover my unitttest tests. Maybe this is due to unittest’s discovery, it seems a bit pickier than PyTest’s.
In the meantime, we gave up using Spyder for software development at my company, it is too limited. We use PyCharm instead.
Note to self: Keep an eye on the Run plugin, PR spyder-ide/spyder#17467, maybe debugging will be implemented through this.
I'm using (similar to above)
'''Debug Pytest in IDE.'''
from pdb import set_trace
from pytest import main
set_trace() # pylint:disable=forgotten-debug-statement
main()
Can spyder-unittest add a menu item called Debug unit tests Alt+Shift+F12
in the Debug menu to start the above?