Skip to content

Commit 73a0e9d

Browse files
authored
handle skip unittest at file without error (#21678)
fixes #21653
1 parent 9bcb82d commit 73a0e9d

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import unittest
5+
from unittest import SkipTest
6+
7+
# Due to the skip at the file level, no tests will be discovered.
8+
raise SkipTest("Skip all tests in this file, they should not be recognized by pytest.")
9+
10+
11+
class SimpleTest(unittest.TestCase):
12+
def testadd1(self):
13+
assert True

pythonFiles/tests/pytestadapter/expected_discovery_test_output.py

+10
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,16 @@
100100
"id_": TEST_DATA_PATH_STR,
101101
}
102102

103+
# This is the expected output for the unittest_skip_file_level test.
104+
# └── unittest_skiptest_file_level.py
105+
unittest_skip_file_level_expected_output = {
106+
"name": ".data",
107+
"path": TEST_DATA_PATH_STR,
108+
"type_": "folder",
109+
"children": [],
110+
"id_": TEST_DATA_PATH_STR,
111+
}
112+
103113
# This is the expected output for the unittest_folder tests
104114
# └── unittest_folder
105115
# ├── test_add.py

pythonFiles/tests/pytestadapter/test_discovery.py

+4
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ def test_parameterized_error_collect():
8787
@pytest.mark.parametrize(
8888
"file, expected_const",
8989
[
90+
(
91+
"unittest_skiptest_file_level.py",
92+
expected_discovery_test_output.unittest_skip_file_level_expected_output,
93+
),
9094
(
9195
"param_same_name",
9296
expected_discovery_test_output.param_same_name_expected_output,

pythonFiles/vscode_pytest/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ def pytest_exception_interact(node, call, report):
7373
# if discovery, then add the error to error logs.
7474
if type(report) == pytest.CollectReport:
7575
if call.excinfo and call.excinfo.typename != "AssertionError":
76+
if report.outcome == "skipped" and "SkipTest" in str(call):
77+
return
7678
ERRORS.append(
7779
call.excinfo.exconly() + "\n Check Python Test Logs for more details."
7880
)

0 commit comments

Comments
 (0)