Created
June 13, 2013 08:30
-
-
Save dzen/5772121 to your computer and use it in GitHub Desktop.
Use unittest.mock.Mock (python 3.3) with factoryboy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import factory | |
import string | |
import random | |
from unittest.mock import Mock | |
class ThingFactory(factory.Factory): | |
FACTORY_FOR = Mock | |
number = factory.Sequence(lambda n: n, type=int) | |
string = factory.Sequence(lambda _:''.join(random.choice(string.ascii_uppercase) for x in range(4))) | |
date = factory.Sequence(lambda _: datetime.datetime.utcnow()) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: from factories import ThingFactory | |
In [2]: thing = ThingFactory() | |
In [3]: thing | |
Out[3]: <Mock id='4367330448'> | |
In [4]: thing.date | |
Out[4]: datetime.datetime(2013, 6, 13, 8, 4, 0, 659616) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment