0
0
PyTesttesting~5 mins

@pytest.mark.skip with reason

Choose your learning style9 modes available
Introduction

Sometimes you want to skip a test on purpose and explain why. This helps keep your test results clear and understandable.

When a feature is not ready but you want to keep the test in the code.
When a test depends on an external system that is temporarily unavailable.
When a test is broken due to a known bug that is being fixed.
When you want to skip a test on certain platforms or environments.
When you want to document why a test is not run currently.
Syntax
PyTest
@pytest.mark.skip(reason="your reason here")
def test_function():
    # test code

The reason explains why the test is skipped and shows in the test report.

Use this decorator above the test function you want to skip.

Examples
This test is skipped because the feature is not ready.
PyTest
@pytest.mark.skip(reason="Feature not implemented yet")
def test_new_feature():
    assert False
This test is skipped because the external API is temporarily unavailable.
PyTest
@pytest.mark.skip(reason="External API down")
def test_api_call():
    response = call_api()
    assert response.status_code == 200
Sample Program

The first test is skipped with a reason shown in the report. The second test runs normally and passes.

PyTest
import pytest

@pytest.mark.skip(reason="Waiting for bug fix #123")
def test_example():
    assert 1 == 2

def test_normal():
    assert 1 == 1
OutputSuccess
Important Notes

Skipped tests do not run, so their code is not executed.

Always provide a clear reason to help others understand why the test is skipped.

Summary

@pytest.mark.skip lets you skip tests with a clear reason.

Skipped tests show in reports but do not run.

Use it to keep your test suite clean and understandable.