Hide keyboard shortcuts

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 

2 

3from faker import Faker 

4from faker.config import DEFAULT_LOCALE 

5 

6DEFAULT_SEED = 0 

7 

8 

9@pytest.fixture(scope='session', autouse=True) 

10def _session_faker(request): 

11 """Fixture that stores the session level ``Faker`` instance. 

12 

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) 

21 

22 

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') 

31 

32 seed = DEFAULT_SEED 

33 if 'faker_seed' in request.fixturenames: 

34 seed = request.getfixturevalue('faker_seed') 

35 fake.seed_instance(seed=seed) 

36 

37 return fake