📚 Cheatsheet

Une collection organisée de snippets de code pour accélérer votre développement. Parcourez, recherchez et copiez en un clic.

Snippets 6

Retour
Pytest - Assertion de base 'assert'
Facile
x = 5
assert x > 0
Pytest - Fixtures pour l'initialisation
Intermédiaire
@pytest.fixture
def mon_objet():
    return {"nom": "test"}

def test_avec_fixture(mon_objet):
    assert mon_objet["nom"] == "test"
Pytest - Marquer un test pour le sauter
Facile
@pytest.mark.skip(reason="Pas encore implémenté")
def test_nouvelle_fonctionnalite():
    pass
Pytest - Structure d'un test
Facile
def test_addition():
    assert 1 + 1 == 2
Pytest - Tester les exceptions
Intermédiaire
import pytest

def test_division_par_zero():
    with pytest.raises(ZeroDivisionError):
        1 / 0
Pytest - Tests paramétrés
Avancé
@pytest.mark.parametrize("entree, attendu", [(1, 2), (3, 4)])
def test_increment(entree, attendu):
    assert entree + 1 == attendu