Skip to content

Instantly share code, notes, and snippets.

@jsok
Created December 7, 2012 12:50
Show Gist options
  • Save jsok/4233063 to your computer and use it in GitHub Desktop.
Save jsok/4233063 to your computer and use it in GitHub Desktop.
factory_boy Sequence customisation

factory_boy Sequence

factory_boy allows you to define attributes as sequences, e.g.:

class MyFactory(factory.Factory):
    id = factory.Sequence(lambda n: "ID%s" % n)

By default, the sequence type is a str.

However if you want to do some trickier formatting you can use the type keyword. So to get "ORD000", "ORD001", etc. sequence:

class OrderFactory(factory.Factory):
    id = factory.Sequence(lambda n: "ID%03d" % n, type=int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment