Skip to content

Commit

Permalink
Add documentation on how to use unique with faker.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurHamon2 committed Nov 23, 2020
1 parent 45b7265 commit 4345ffa
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ChangeLog

- Add support for Django 3.1
- Add support for Python 3.9
- Add support for `unique` Faker feature

*Removed:*

Expand Down
18 changes: 18 additions & 0 deletions docs/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,24 @@ Faker
date_end=datetime.date(2020, 5, 31),
)
Since Faker 4.9.0 version (see `Faker documentation <https://faker.readthedocs.io/en/master/fakerclass.html#unique-values>`_),
on every provider, you can specify whether to return an unique value or not:

.. code-block:: python
class UserFactory(fatory.Factory):
class Meta:
model = User
arrival = factory.Faker(
'date_between_dates',
date_start=datetime.date(2020, 1, 1),
date_end=datetime.date(2020, 5, 31),
unique=True # The generated date is guaranteed to be unique inside the test execution.
)
Note that an `UniquenessException` will be thrown if Faker fails to generate an unique value.

As with :class:`~factory.SubFactory`, the parameters can be any valid declaration.
This does not apply to the provider name or the locale.

Expand Down

0 comments on commit 4345ffa

Please sign in to comment.