Reputation: 4126
I would like to attach a debugger while running the unittest module. I can't seem to find any info about this via the google. Does anyone have a config that would allow debugging into the python test runner? The other this is that i use the discover arg to match my test pattern. I don't mind having to debug individual files but it would be nice to just fire the debugger with a config i don't need to monkey with whenever i need to change to a different file.
python -m unittest discover -p "*_test.py"
I've tried adding this config
{
"name": "Python: Unittest",
"type": "python",
"request": "launch",
"module": "unittest",
"args": ["discover", "-p", "'*_test.py'"]
},
but i get no matches found: '*_test.py'
error...
anyone got ideas? another way to debug into the unittest runner?
Upvotes: 6
Views: 16784
Reputation: 9521
1.Press Ctrl+Shift+P to open Command Platte;
2.Select Python: Discover Tests, there'll be a notification to let you Enable and configure a Test Framework:
3.Choose Unittest, then you can choose the option to identify test files:
Above all is written in workspace settings.json:
So you can set the identification rule by the setting:
"python.testing.unittestArgs":[]
About Debug all tests, the Python: Debug All Tests and Python: Debug Test Method commands (on both the Command Palette and Status Bar menu) launch the debugger for all tests and a single test method, respectively.
More detailed information, please refer to Testing and Debug Tests.
Upvotes: 6