Skip to content

Commit

Permalink
support skip in fixture (#24588)
Browse files Browse the repository at this point in the history
fixes #24547
  • Loading branch information
eleanorjboyd authored Dec 12, 2024
1 parent e8f710a commit c0ea185
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
19 changes: 19 additions & 0 deletions python_files/tests/pytestadapter/.data/skip_test_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import pytest


@pytest.fixture
def docker_client() -> object:
try:
# NOTE: Actually connect with the docker sdk
raise Exception("Docker client not available")
except Exception:
pytest.skip("Docker client not available")

return object()


def test_docker_client(docker_client):
assert False
13 changes: 13 additions & 0 deletions python_files/tests/pytestadapter/expected_execution_test_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,3 +734,16 @@
"subtest": None,
},
}

skip_test_fixture_path = TEST_DATA_PATH / "skip_test_fixture.py"
skip_test_fixture_execution_expected_output = {
get_absolute_test_id("skip_test_fixture.py::test_docker_client", skip_test_fixture_path): {
"test": get_absolute_test_id(
"skip_test_fixture.py::test_docker_client", skip_test_fixture_path
),
"outcome": "skipped",
"message": None,
"traceback": None,
"subtest": None,
}
}
5 changes: 5 additions & 0 deletions python_files/tests/pytestadapter/test_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ def test_rootdir_specified():
expected_execution_test_output.nested_describe_expected_execution_output,
id="nested_describe_plugin",
),
pytest.param(
["skip_test_fixture.py::test_docker_client"],
expected_execution_test_output.skip_test_fixture_execution_expected_output,
id="skip_test_fixture",
),
],
)
def test_pytest_execution(test_ids, expected_const):
Expand Down
2 changes: 1 addition & 1 deletion python_files/vscode_pytest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def pytest_report_teststatus(report, config): # noqa: ARG001
if SYMLINK_PATH:
cwd = SYMLINK_PATH

if report.when == "call":
if report.when == "call" or (report.when == "setup" and report.skipped):
traceback = None
message = None
report_value = "skipped"
Expand Down

0 comments on commit c0ea185

Please sign in to comment.