Skip to content

Commit c0ea185

Browse files
authored
support skip in fixture (#24588)
fixes #24547
1 parent e8f710a commit c0ea185

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
import pytest
5+
6+
7+
@pytest.fixture
8+
def docker_client() -> object:
9+
try:
10+
# NOTE: Actually connect with the docker sdk
11+
raise Exception("Docker client not available")
12+
except Exception:
13+
pytest.skip("Docker client not available")
14+
15+
return object()
16+
17+
18+
def test_docker_client(docker_client):
19+
assert False

python_files/tests/pytestadapter/expected_execution_test_output.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,3 +734,16 @@
734734
"subtest": None,
735735
},
736736
}
737+
738+
skip_test_fixture_path = TEST_DATA_PATH / "skip_test_fixture.py"
739+
skip_test_fixture_execution_expected_output = {
740+
get_absolute_test_id("skip_test_fixture.py::test_docker_client", skip_test_fixture_path): {
741+
"test": get_absolute_test_id(
742+
"skip_test_fixture.py::test_docker_client", skip_test_fixture_path
743+
),
744+
"outcome": "skipped",
745+
"message": None,
746+
"traceback": None,
747+
"subtest": None,
748+
}
749+
}

python_files/tests/pytestadapter/test_execution.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ def test_rootdir_specified():
194194
expected_execution_test_output.nested_describe_expected_execution_output,
195195
id="nested_describe_plugin",
196196
),
197+
pytest.param(
198+
["skip_test_fixture.py::test_docker_client"],
199+
expected_execution_test_output.skip_test_fixture_execution_expected_output,
200+
id="skip_test_fixture",
201+
),
197202
],
198203
)
199204
def test_pytest_execution(test_ids, expected_const):

python_files/vscode_pytest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ def pytest_report_teststatus(report, config): # noqa: ARG001
265265
if SYMLINK_PATH:
266266
cwd = SYMLINK_PATH
267267

268-
if report.when == "call":
268+
if report.when == "call" or (report.when == "setup" and report.skipped):
269269
traceback = None
270270
message = None
271271
report_value = "skipped"

0 commit comments

Comments
 (0)