<filename>tests/test_locale_override.py
import string

import factory
from pytest_factoryboy import register

from mimesis_factory import MimesisField


class Person(object):
    def __init__(self, full_name_en: str, full_name_ru: str) -> None:
        self._full_name_en = full_name_en
        self._full_name_ru = full_name_ru

    @property
    def full_name_en(self) -> str:
        """Some names have special symbols in them."""
        return self._full_name_en.replace(' ', '').replace("'", '')

    @property
    def full_name_ru(self) -> str:
        """Some names have special symbols in them."""
        return self._full_name_ru.replace(' ', '').replace("'", '')


@register
class PersonFactory(factory.Factory):
    class Meta(object):
        model = Person

    full_name_en = MimesisField('full_name')
    full_name_ru = MimesisField('full_name', locale='ru')


def test_data_with_different_locales(person):
    for letter in person.full_name_en:
        assert letter in string.ascii_letters

    for russian_letter in person.full_name_ru:
        assert russian_letter not in string.ascii_letters


def test_data_with_override_locale(person_factory):
    with MimesisField.override_locale('ru'):
        person = person_factory()

    for letter in person.full_name_en:
        # Default locale will be changed to overridden:
        assert letter not in string.ascii_letters

    for russian_letter in person.full_name_ru:
        assert russian_letter not in string.ascii_letters


def test_data_with_override_defined_locale(person_factory):
    with MimesisField.override_locale('en'):
        person = person_factory()

    for letter in person.full_name_en:
        assert letter in string.ascii_letters

    for russian_letter in person.full_name_ru:
        # Keyword locale has a priority over override:
        assert russian_letter not in string.ascii_letters

<filename>tests/test_locale_override.py
import string

import factory
from pytest_factoryboy import register

from mimesis_factory import MimesisField


class Person(object):
    def __init__(self, full_name_en: str, full_name_ru: str) -> None:
        self._full_name_en = full_name_en
        self._full_name_ru = full_name_ru

    @property
    def full_name_en(self) -> str:
        """Some names have special symbols in them."""
        return self._full_name_en.replace(' ', '').replace("'", '')

    @property
    def full_name_ru(self) -> str:
        """Some names have special symbols in them."""
        return self._full_name_ru.replace(' ', '').replace("'", '')


@register
class PersonFactory(factory.Factory):
    class Meta(object):
        model = Person

    full_name_en = MimesisField('full_name')
    full_name_ru = MimesisField('full_name', locale='ru')


def test_data_with_different_locales(person):
    for letter in person.full_name_en:
        assert letter in string.ascii_letters

    for russian_letter in person.full_name_ru:
        assert russian_letter not in string.ascii_letters


def test_data_with_override_locale(person_factory):
    with MimesisField.override_locale('ru'):
        person = person_factory()

    for letter in person.full_name_en:
        # Default locale will be changed to overridden:
        assert letter not in string.ascii_letters

    for russian_letter in person.full_name_ru:
        assert russian_letter not in string.ascii_letters


def test_data_with_override_defined_locale(person_factory):
    with MimesisField.override_locale('en'):
        person = person_factory()

    for letter in person.full_name_en:
        assert letter in string.ascii_letters

    for russian_letter in person.full_name_ru:
        # Keyword locale has a priority over override:
        assert russian_letter not in string.ascii_letters

Some names have special symbols in them. Some names have special symbols in them. # Default locale will be changed to overridden: # Keyword locale has a priority over override: