Skip to content
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

Can't run unittests in debug mode? #126

Open
joeyCorea opened this issue Jan 19, 2019 · 6 comments
Open

Can't run unittests in debug mode? #126

joeyCorea opened this issue Jan 19, 2019 · 6 comments

Comments

@joeyCorea
Copy link

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
@acudworth3
Copy link

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

@ocroquette
Copy link

ocroquette commented Apr 2, 2020

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

@jitseniesen jitseniesen added this to the v0.5.1 milestone Jan 6, 2022
@jitseniesen jitseniesen removed the v0.5.0 label Jan 6, 2022
@jitseniesen jitseniesen modified the milestones: v0.5.1, v0.5.2 Aug 17, 2022
@jitseniesen jitseniesen removed their assignment Aug 17, 2022
@hanasaki
Copy link

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

@ocroquette
Copy link

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.

@jitseniesen
Copy link
Member

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

@jitseniesen jitseniesen modified the milestones: v0.5.2, v0.6.0 Mar 24, 2023
@jitseniesen jitseniesen modified the milestones: v0.6.0, v0.7.0 Jun 10, 2023
@PanderMusubi
Copy link

PanderMusubi commented Nov 22, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants