pytest-dev / pytest-dev/pytest-factoryboy

No parameters generated for model-only attributres

Open
#23 11 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
400
Forks
44
Avg merge
6h 34m
Merged PRs (30d)
1

Description

No parameters are generated for model-only parameters. We often have Django model defaults which we don't override in factories, but do override in tests. For example:

class Book(models.Model):
    title = models.CharField(max_length=255, default='My title')


class BookFactory(factory.DjangoModelFactory):
    class Meta:
        model = Book


register(BookFactory)


@pytest.mark.django_db
@pytest.mark.parametrize('book__title', ['My other title'])
def test_title(book):
    assert book.title == 'My other title'

This results in ValueError: <function test_title at 0x7efe970a2488> uses no fixture 'book__title'

If I add the title to the BookFactory it does work.

Result of pip freeze:

Django==1.9.6
factory-boy==2.7.0
fake-factory==0.5.7
inflection==0.3.1
ipaddress==1.0.16
py==1.4.31
pytest==2.9.1
pytest-django==2.9.1
pytest-factoryboy==1.1.6
python-dateutil==2.5.3
six==1.10.0

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the Django model-only attribute example from the issue and tracing how pytest-factoryboy discovers factory parameters. Done means the parametrized book__title fixture is generated and the example test passes without adding title to BookFactory.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend, testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.