django-fakery icon indicating copy to clipboard operation
django-fakery copied to clipboard

Makes shortcuts a fixture

Open sobolevn opened this issue 4 years ago • 2 comments

I end up importing shortcuts in almost every module. I guess, that it would much more convenient to use:

def test_with_some_date(fakery, shortcuts):
     ...

I hope this is a good idea :)

sobolevn avatar Dec 06 '19 10:12 sobolevn

Coverage Status

Coverage decreased (-0.5%) to 92.398% when pulling 02b0c265b9067b68cddfc31ea72f9f0bdf4872a8 on sobolevn:patch-1 into f071b5937f502eb8d144a2e7bfce9822fa3afbef on fcurella:master.

coveralls avatar Dec 06 '19 10:12 coveralls

I agree that there should a more convenient way to access the shortcuts, but I'm worried about name conflicts. I think shortcuts may be too generic of a name for a fixture. We could call it fakery_shortcuts, or something like that.

Alternatively, we could try just making the shortcuts module available as a property of Factory:

# faker_factory.py
from . import shortcuts


class Factory(Generic[T]):
    shortcurts = shortcuts

    # ... rest of the class

This way we just need one fixture:

def mytest(fakery):
    fakery.m(MyModel)(field=fakery.shortcuts.future_datetime('+1w'))

fcurella avatar Dec 06 '19 15:12 fcurella