Skip to content

Commit

Permalink
handle skip unittest at file without error (#21678)
Browse files Browse the repository at this point in the history
fixes #21653
  • Loading branch information
eleanorjboyd committed Jul 24, 2023
1 parent 9bcb82d commit 73a0e9d
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import unittest
from unittest import SkipTest

# Due to the skip at the file level, no tests will be discovered.
raise SkipTest("Skip all tests in this file, they should not be recognized by pytest.")


class SimpleTest(unittest.TestCase):
def testadd1(self):
assert True
10 changes: 10 additions & 0 deletions pythonFiles/tests/pytestadapter/expected_discovery_test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@
"id_": TEST_DATA_PATH_STR,
}

# This is the expected output for the unittest_skip_file_level test.
# └── unittest_skiptest_file_level.py
unittest_skip_file_level_expected_output = {
"name": ".data",
"path": TEST_DATA_PATH_STR,
"type_": "folder",
"children": [],
"id_": TEST_DATA_PATH_STR,
}

# This is the expected output for the unittest_folder tests
# └── unittest_folder
# ├── test_add.py
Expand Down
4 changes: 4 additions & 0 deletions pythonFiles/tests/pytestadapter/test_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ def test_parameterized_error_collect():
@pytest.mark.parametrize(
"file, expected_const",
[
(
"unittest_skiptest_file_level.py",
expected_discovery_test_output.unittest_skip_file_level_expected_output,
),
(
"param_same_name",
expected_discovery_test_output.param_same_name_expected_output,
Expand Down
2 changes: 2 additions & 0 deletions pythonFiles/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ def pytest_exception_interact(node, call, report):
# if discovery, then add the error to error logs.
if type(report) == pytest.CollectReport:
if call.excinfo and call.excinfo.typename != "AssertionError":
if report.outcome == "skipped" and "SkipTest" in str(call):
return
ERRORS.append(
call.excinfo.exconly() + "\n Check Python Test Logs for more details."
)
Expand Down

0 comments on commit 73a0e9d

Please sign in to comment.