Thursday, May 5, 2016

Re: Fixtures won't load twice in same testcase

On 6/05/2016 8:42 AM, Rich Rauenzahn wrote:
>
> I've been tracing into django core code, and it looks to me that I have
> a case where the fixture has a auth.User(username=rich) with a pk=1 in
> the fixture. Â But sometimes as the User fixture with pk=1 is being
> added (updated?) through Model._save_table(), the same User with pk=5 is
> already in the db (did not exist prior to fixture loading). Â This
> causes the django core code (Model._save_table()) to also try to insert
> another user with the same username, causing an integrity error.
>
> I added my own _fixture_setup() that asserted my db was clean prior to
> fixture loading. Â It failed! Â This lead me to find objects being
> created in a TestCase.setUpClass rather than TestCase.setUp(), and so
> were leaking across tests, fouling up fixture loading.
>
> What's odd is that django-nose's FastFixtureTestCase hid this problem.
> Â .... I think it affected the ordering and ran all the fixture based
> test cases first before the db was polluted. Â (But isn't the DB
> dropped and refreshed after every TestCase?)

Are you using setUp() and tearDown() as class methods in your test class?

>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscribe@googlegroups.com
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto:django-users@googlegroups.com>.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/c9d604a9-af10-4e22-91de-f81f3986d28d%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/c9d604a9-af10-4e22-91de-f81f3986d28d%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cccd7fdd-2c33-0490-a086-245c41cf3dfc%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment