Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Traits not being considered by pytest_factoryboy #220

Open
youtux opened this issue May 10, 2024 · 2 comments
Open

Traits not being considered by pytest_factoryboy #220

youtux opened this issue May 10, 2024 · 2 comments

Comments

@youtux
Copy link
Contributor

youtux commented May 10, 2024

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
Copy link

Same here. Is there any workaround this ?

@an0o0nym
Copy link

an0o0nym commented Sep 19, 2024

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants