summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorRaphaël Barrois <raphael.barrois@polytechnique.org>2013-04-15 02:21:08 +0200
committerRaphaël Barrois <raphael.barrois@polytechnique.org>2013-04-15 02:21:08 +0200
commite7a9a87320c78ec05a5d548516fe17c258e6d4c7 (patch)
tree78d92de6e928ded94f7fda979be6f560844aff85 /docs
parent54971381fb31167d1f47b5e705480e044d702602 (diff)
downloadfactory-boy-e7a9a87320c78ec05a5d548516fe17c258e6d4c7.tar
factory-boy-e7a9a87320c78ec05a5d548516fe17c258e6d4c7.tar.gz
Allow overriding the sequence counter.
Diffstat (limited to 'docs')
-rw-r--r--docs/changelog.rst1
-rw-r--r--docs/reference.rst31
2 files changed, 32 insertions, 0 deletions
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 100952c..80074ae 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -14,6 +14,7 @@ ChangeLog
- Add support for ``get_or_create`` in :class:`~factory.DjangoModelFactory`,
through :attr:`~factory.DjangoModelFactory.FACTORY_DJANGO_GET_OR_CREATE`.
- Add support for :mod:`~factory.fuzzy` attribute definitions.
+ - The :class:`Sequence` counter can be overridden when calling a generating function
*Removed:*
diff --git a/docs/reference.rst b/docs/reference.rst
index a2af327..13220b0 100644
--- a/docs/reference.rst
+++ b/docs/reference.rst
@@ -502,6 +502,37 @@ sequence counter is shared:
'123-555-0003'
+Forcing a sequence counter
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If a specific value of the sequence counter is required for one instance, the
+``__sequence`` keyword argument should be passed to the factory method.
+
+This will force the sequence counter during the call, without altering the
+class-level value.
+
+.. code-block:: python
+
+ class UserFactory(factory.Factory):
+ FACTORY_FOR = User
+
+ uid = factory.Sequence(int)
+
+.. code-block:: pycon
+
+ >>> UserFactory()
+ <User: 0>
+ >>> UserFactory()
+ <User: 1>
+ >>> UserFactory(__sequence=42)
+ <User: 42>
+
+
+.. warning:: The impact of setting ``__sequence=n`` on a ``_batch`` call is
+ undefined. Each generated instance may share a same counter, or
+ use incremental values starting from the forced value.
+
+
LazyAttributeSequence
"""""""""""""""""""""