diff --git a/python_files/tests/pytestadapter/.data/skip_test_fixture.py b/python_files/tests/pytestadapter/.data/skip_test_fixture.py new file mode 100644 index 000000000000..3d354cae86ea --- /dev/null +++ b/python_files/tests/pytestadapter/.data/skip_test_fixture.py @@ -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 diff --git a/python_files/tests/pytestadapter/expected_execution_test_output.py b/python_files/tests/pytestadapter/expected_execution_test_output.py index 8f378074343d..fa6743d0e112 100644 --- a/python_files/tests/pytestadapter/expected_execution_test_output.py +++ b/python_files/tests/pytestadapter/expected_execution_test_output.py @@ -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, + } +} diff --git a/python_files/tests/pytestadapter/test_execution.py b/python_files/tests/pytestadapter/test_execution.py index 245b13cf5d46..27fd1160441b 100644 --- a/python_files/tests/pytestadapter/test_execution.py +++ b/python_files/tests/pytestadapter/test_execution.py @@ -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): diff --git a/python_files/vscode_pytest/__init__.py b/python_files/vscode_pytest/__init__.py index 59a1b75e9688..58d4b72fc46e 100644 --- a/python_files/vscode_pytest/__init__.py +++ b/python_files/vscode_pytest/__init__.py @@ -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"