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

Typecaster configuration lost across pytest-django test runs #16

Open
dalberto opened this issue Jul 31, 2017 · 1 comment
Open

Typecaster configuration lost across pytest-django test runs #16

dalberto opened this issue Jul 31, 2017 · 1 comment

Comments

@dalberto
Copy link

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.

@danni
Copy link
Owner

danni commented Aug 1, 2017

I've not used pytest-django, so I don't know how it initialises the database. Can you reduce it down to a test case?

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