Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/faker/contrib/pytest/plugin.py : 16%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import pytest
3from faker import Faker
4from faker.config import DEFAULT_LOCALE
6DEFAULT_SEED = 0
9@pytest.fixture(scope='session', autouse=True)
10def _session_faker(request):
11 """Fixture that stores the session level ``Faker`` instance.
13 This fixture is internal and is only meant for use within the project.
14 Third parties should instead use the ``faker`` fixture for their tests.
15 """
16 if 'faker_session_locale' in request.fixturenames:
17 locale = request.getfixturevalue('faker_session_locale')
18 else:
19 locale = [DEFAULT_LOCALE]
20 return Faker(locale=locale)
23@pytest.fixture()
24def faker(request):
25 """Fixture that returns a seeded and suitable ``Faker`` instance."""
26 if 'faker_locale' in request.fixturenames:
27 locale = request.getfixturevalue('faker_locale')
28 fake = Faker(locale=locale)
29 else:
30 fake = request.getfixturevalue('_session_faker')
32 seed = DEFAULT_SEED
33 if 'faker_seed' in request.fixturenames:
34 seed = request.getfixturevalue('faker_seed')
35 fake.seed_instance(seed=seed)
37 return fake