pytest-dev / pytest-factoryboy

factory_boy integration the pytest runner
MIT License
359 stars 42 forks source link

`Trait`s not being considered by pytest_factoryboy #220

Open youtux opened 4 months ago

youtux commented 4 months ago

Given a factory with traits, pytest_factoryboy should treat them as normal params, and allow them to be parametrized.

MCVE:

@dataclass
class Article:
    comments: int
    views: int

@register
class ArticleFactory(Factory):
    class Meta:
        model = Article

    class Params:
        boring = Trait(
            comments=0,
            views=0,
        )
    comments = 10
    views = 1000

@pytest.mark.parametrize("article__boring", [True])
def test_boring_article(article):
    assert article.comments == 0
    assert article.views == 0
an0o0nym commented 1 week ago

Same here. Is there any workaround this ?

an0o0nym commented 1 week ago

I guess the only workaround for now is to use custom fixtures.So for given MCVE would be something like:

@pytest.fixture()
def boring_article():
  return ArticleFactory(boring=True)