spyder-unittest icon indicating copy to clipboard operation
spyder-unittest copied to clipboard

Can't run unittests in debug mode?

Open joeyCorea opened this issue 6 years ago • 6 comments

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?

  1. Set a breakpoint in a unit test or code the unit test exercises.
  2. 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

joeyCorea avatar Jan 19 '19 05:01 joeyCorea

Any plans to address this issue? I am seeing the exact same issue.

acudworth3 avatar Apr 14 '19 00:04 acudworth3

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()

ocroquette avatar Apr 02 '20 06:04 ocroquette

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()

hanasaki avatar Oct 23 '22 01:10 hanasaki

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.

ocroquette avatar Oct 24 '22 05:10 ocroquette

Note to self: Keep an eye on the Run plugin, PR spyder-ide/spyder#17467, maybe debugging will be implemented through this.

jitseniesen avatar Feb 09 '23 21:02 jitseniesen

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?

PanderMusubi avatar Nov 22 '23 13:11 PanderMusubi