You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New pythonTestAdapter does not work with unittest.SkipTest #21653
The new pythonTestAdapter errors out instead of skipping the test.
Steps to reproduce:
Have a file like this in your test folder:
fromunittestimportSkipTestraiseSkipTest("This is unittest.SkipTest calling")
deftest_example():
assert1==1
Diagnostic data
Python version (& distribution if applicable, e.g. Anaconda): 3.10.12
Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Conda
Value of the python.languageServer setting: Pylance
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
2023-07-18 20:47:13.010 [error] pytest test discovery error
unittest.case.SkipTest: This is unittest.SkipTest calling
Check Python Test Logs for more details.
Can you describe what you mean by erroring? When I try this I see it listed as "not run". This is expected because the extension doesn't know the test exists because the skipTest line throws an exception. That folder then can't run since it has no tests and cannot return a skipped value for the icon. Let me know if I misunderstood your bug report, thanks!
So if you raise a skipTest in the file but not in a function/ class specifically it will skip the whole test file.
for example:
from unittest import SkipTest
raise SkipTest("This is unittest.SkipTest calling")
def test_example():
assert 1 == 1
def test_two():
assert True
then if you run unittest from the command line you can see test_folder_unit_skip (unittest.loader.ModuleSkipped) ... skipped 'This is unittest.SkipTest calling' and so it wont recognize the individual tests since it stops when looking in the whole file.
as opposed to
import unittest
def add(x, y):
return x + y
class SimpleTest(unittest.TestCase):
@unittest.skip("demonstrating skipping")
def testadd1(self):
self.assertEquals(add(4, 5), 9)
class OtherTest(unittest.TestCase):
def testtwo(self):
self.assertEquals(add(4, 5), 9)
if __name__ == "__main__":
unittest.main()
where the testadd1 will be discovered (and labeled as skipped) and testtwo will be discovered and can run since the skip is inside the class. Then if I put these in separate files, the testadd1 will be found but skipped and testtwo will be found and run (so same deal just under different file nodes in the same folder).
I did find one issue with unittest discovery for skip and so I have submitted it here: #21665. This won't change run behavior but will fix the test explorer in that the node isn't correct for file level skip tests. So now if you have root/skip_test_at_file_level and root/no_skip then the node root should exist with two children (which is not happening right now instead there are two top level nodes one of them called "unittest")
2023-07-20 10:06:36.509 [error] pytest test discovery error
unittest.case.SkipTest: This is unittest.SkipTest calling
Check Python Test Logs for more details.
putting this here with the info I have. Might be delayed a bit getting to it as this is not a regression and this behavior didn't work before either.
With pytest enabled, files with raise SkipTest("This is unittest.SkipTest calling") should not error instead discovery should work correctly with those tests not being discovered since it is skipped at the file level. Below is a test case that should result in the file being shown as a node but not the error or any tests in the folder. This is not a regression since the old code does not handle this but it discovery should work correctly as you can test in the command line.
import unittest
from unittest import SkipTest
raise SkipTest("This is unittest.SkipTest calling")
class SimpleTest(unittest.TestCase):
@unittest.skip("demonstrating skipping")
def testadd1(self):
assert True
Activity
eleanorjboyd commentedon Jul 19, 2023
Can you describe what you mean by erroring? When I try this I see it listed as "not run". This is expected because the extension doesn't know the test exists because the skipTest line throws an exception. That folder then can't run since it has no tests and cannot return a skipped value for the icon. Let me know if I misunderstood your bug report, thanks!
hoxbro commentedon Jul 19, 2023
Did you have other test files with test functions in the folder?
They should be discoverable, right?
eleanorjboyd commentedon Jul 19, 2023
So if you raise a skipTest in the file but not in a function/ class specifically it will skip the whole test file.
for example:
then if you run unittest from the command line you can see
test_folder_unit_skip (unittest.loader.ModuleSkipped) ... skipped 'This is unittest.SkipTest calling'and so it wont recognize the individual tests since it stops when looking in the whole file.as opposed to
where the
testadd1will be discovered (and labeled as skipped) andtesttwowill be discovered and can run since the skip is inside the class. Then if I put these in separate files, thetestadd1will be found but skipped andtesttwowill be found and run (so same deal just under different file nodes in the same folder).I did find one issue with unittest discovery for skip and so I have submitted it here: #21665. This won't change run behavior but will fix the test explorer in that the node isn't correct for file level skip tests. So now if you have root/skip_test_at_file_level and root/no_skip then the node root should exist with two children (which is not happening right now instead there are two top level nodes one of them called "unittest")
hoxbro commentedon Jul 20, 2023
I'm seeing this problem when running with
pytestEnabled, this is mysettings.json:{ "python.testing.pytestArgs": [ "." ], "python.testing.unittestEnabled": false, "python.testing.pytestEnabled": true }And I have these two files:
And in the Python Ouput I get this:
If I comment out the
raise SkipTestI get this:eleanorjboyd commentedon Jul 21, 2023
able to repro now- sorry my settings were wrong. I will put a fix in for this soon! Thanks
eleanorjboyd commentedon Jul 21, 2023
putting this here with the info I have. Might be delayed a bit getting to it as this is not a regression and this behavior didn't work before either.
With pytest enabled, files with
raise SkipTest("This is unittest.SkipTest calling")should not error instead discovery should work correctly with those tests not being discovered since it is skipped at the file level. Below is a test case that should result in the file being shown as a node but not the error or any tests in the folder. This is not a regression since the old code does not handle this but it discovery should work correctly as you can test in the command line.handle skip unittest at file without error (#21678)
Merged PR posit-dev/positron-python#213: Merge python extension relea…
Merged PR posit-dev/positron-python#213: Merge python extension relea…