Skip to content

PytestAssertRewriteWarning #187

Open
@helioascorreia

Description

@helioascorreia

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions