def test_person_validate_nirs(nir, expected): person = Person( first_name='a', last_name='b', nir=nir, birth_date='1969-01-01', email="*****@*****.**", ) if not expected: person.full_clean() assert person.nir == str(nir) else: with pytest.raises(ValidationError) as raised: person.full_clean() assert len(raised.value.error_dict['nir']) == expected