Skip to content

Typecaster configuration lost across pytest-django test runs #16

@dalberto

Description

@dalberto

When running a test suite in a project that uses django-postgres-composite-types I observed some unexpected behavior. The test suite succeeded on the first run (as expected). However, when re-running the test suite, tests that exercised models that have composite types, failed with an error like:

AttributeError: 'str' object has no attribute 'my_field'

After further inspection, I found that the types were not correctly cast in subsequent runs (even though they were always correctly persisted). In subsequent runs, the type for the composite type field was indeed str, while during the first run it was the correct type.

My workaround is to simply call the type's register_composite method at the very beginning of the test run in conftest.py (I'm using py.test).

This issue does not manifest itself when running Django's development server or when running Django with gunicorn, so it can very well have something to do with how the test suite is configured.

For reference, I'm running:

django 1.11.3
psycopg2 2.7.3
pytest 3.1.3
pytest-django 3.1.2

I'm also running pytest-django with the the --reuse-db flag, so migrations are not re-run, including MyType.Operation().

As I mentioned this can very well be the result of my test configuration, but any help or guidance would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions