Sobes.tech
Junior — Middle

Cum se poate omite sau dezactiva un test specific în PyTest?

sobes.tech AI

Răspuns de la AI

În PyTest, puteți omite sau dezactiva un test în mai multe moduri:

  1. Utilizați decoratorul @pytest.mark.skip pentru a omite complet testul:
import pytest

@pytest.mark.skip(reason="Motivul omiterii")
def test_example():
    assert False
  1. Utilizați @pytest.mark.skipif pentru a omite condiționat:
import pytest
import sys

@pytest.mark.skipif(sys.platform == "win32", reason="Nu este suportat pe Windows")
def test_unix_only():
    assert True
  1. În interiorul testului, apelați pytest.skip() pentru a omite dinamic:
import pytest

def test_dynamic_skip():
    if not some_condition():
        pytest.skip("Condiție neîndeplinită")
    assert True

Astfel, puteți gestiona flexibil execuția testelor în funcție de condiții sau motive.