Compendium

Python testings with pytest

Stack:

  • Python3.6+
  • Pytest

Casos de testes:

Métodos simples:

Implementação:

def helper():
    return {
    'field_1': 'value_1',
    'field_2': 'value_2'
    }

Validação de tipo:

def test_should_return_a_dict():
    result = helper()

    assert isinstance(result, dict)

Validação de chaves:

def test_should_return_expected_keys():
    expected_keys = {'field_1', 'field_2'}
    result = helper()

    assert set(result.keys()) == expected_keys

validação de valores:

import pytest

@pytest.mark …