Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom faker provider for usage with factory boy and pytest

I am attempting to add some custom faker provider to use with factory_boy and pytest.

I put the provider in faker_providers/foo.py/Provider.

In my factories.py file, I have to import foo.py and then register by running:

factory.Faker.add_provider(foo.Provider)

I am thinking of using pytest_sessionstart(session) to auto-register all the custom provider under faker_providers. Is there a way to do that?

Any suggestions for other ways to organize and register custom providers would also be appreciated.

like image 722
dephiros Avatar asked Nov 08 '22 00:11

dephiros


1 Answers

It seems like a design choice and only you know the best answer to it.

However, I would recommend instantiating faker = Faker() once for all tests after that adding all providers in a configuration file. And import faker from that place to everywhere it's needed.

It seems like conftest.py is a good choice for that.

like image 62
Max Voitko Avatar answered Nov 13 '22 15:11

Max Voitko