Feat/add unique feature arg in faker factory #997
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request follows on from the abandoned #820. The code is simplified and follows the same pattern used when specifying the locale for Faker.
Since Faker 4.9.0 there has been support to generate unique values. This is really helpful when dealing with unique constraint on a field generated by factory boy. The test can be flaky if you use faker without the "unique" feature on an ORM field with an unique constraint.
The usage with factory boy is simple as this:
The unique keyword can be passed on every faker providers. If
True
the faker object passes through the Faker Unique Proxy, making sure the generated value has not been already generated before. Note that the default unique keyword value isFalse
.Credit goes to @arthurHamon2 for the idea and the original pull request.