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:
- Utilizați decoratorul
@pytest.mark.skippentru a omite complet testul:
import pytest
@pytest.mark.skip(reason="Motivul omiterii")
def test_example():
assert False
- Utilizați
@pytest.mark.skipifpentru 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
- Î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.