[Python] @pytest.mark.skip vs @pytest.mark.xfail in Pytest

Discussão em 'Python' iniciado por Stack, Fevereiro 25, 2025.

  1. Stack

    Stack Membro Participativo

    I have @pytest.mark.skip's test1() and @pytest.mark.xfail's test2() which are both True as shown below:

    import pytest

    @pytest.mark.skip
    def test1():
    assert True

    @pytest.mark.xfail
    def test2():
    assert True


    Then, I ran pytest, then there is the output as shown below:

    $ pytest
    =================== test session starts ===================
    platform win32 -- Python 3.9.13, pytest-7.4.0, pluggy-1.2.0
    django: settings: core.settings (from ini)
    rootdir: C:\Users\kai\test-django-project2
    configfile: pytest.ini
    plugins: django-4.5.2
    collected 2 items

    tests\test_store.py sX [100%]

    ============== 1 skipped, 1 xpassed in 0.10s ==============


    Next, I have @pytest.mark.skip's test1() and @pytest.mark.xfail's test2() which are both False as shown below:

    import pytest

    @pytest.mark.skip
    def test1():
    assert False

    @pytest.mark.xfail
    def test2():
    assert False


    Then, I ran pytest, then there is the same output as shown below:

    $ pytest
    =================== test session starts ===================
    platform win32 -- Python 3.9.13, pytest-7.4.0, pluggy-1.2.0
    django: settings: core.settings (from ini)
    rootdir: C:\Users\kai\test-django-project2
    configfile: pytest.ini
    plugins: django-4.5.2
    collected 2 items

    tests\test_store.py sx [100%]

    ============== 1 skipped, 1 xfailed in 0.24s ==============


    So, what is the difference between @pytest.mark.skip and @pytest.mark.xfail?

    Continue reading...

Compartilhe esta Página