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

handle skip unittest at file without error #21678

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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