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

PytestAssertRewriteWarning #187

Open
helioascorreia opened this issue Dec 20, 2022 · 0 comments
Open

PytestAssertRewriteWarning #187

helioascorreia opened this issue Dec 20, 2022 · 0 comments

Comments

@helioascorreia
Copy link

Hello there,
When I run my tests I got the following warning

../../usr/local/lib/python3.11/site-packages/_pytest/config/init.py:747
/usr/local/lib/python3.11/site-packages/_pytest/config/init.py:747: PytestAssertRewriteWarning: Module already imported so cannot be rewritten: products.tests.factories
self.import_plugin(import_spec)

This happens because I have one file of fixtures

@register
class ProductCycleFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = ProductCycle

    product = factory.SubFactory(ProductFactory)
    cycle_id = factory.Faker("numerify", text="#" * 9)
    vat_id = factory.Faker("numerify", text="#" * 9)

And in my other file of fixtures i have

from products.tests.factories import ProductCycleFactory

@register
class InvoiceLineFactory(factory.django.DjangoModelFactory):
    class Meta:
        model = InvoiceLine

    description = factory.Faker("sentence", nb_words=3)
    invoice = factory.SubFactory(InvoiceFactory)
    product_cycle = factory.SubFactory(ProductCycleFactory)

I already try to change to product_cycle = factory.SubFactory("products.tests.factories.ProductCycleFactory")

My requirements

pytest==7.2.0
pytest-django==4.5.2
pytest-factoryboy==2.5.1

Any idea how I solve this warning,
Thanks

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

1 participant