-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

On Sat, Jan 12, 2019 at 03:59:59PM +0200, אורי wrote:
> Hi,
> 
> I have a problem with tests. We defined a class called DefaultUserFactory
> which inherits from factory.DjangoModelFactory, and I want to use asserts
> in this class such as assertEqual. What is the best approach to do it? I
> tried to inherit both from factory.DjangoModelFactory and from Django class
> TestCase but it doesn't work. I thought about passing a parameter from the
> calling function and then call assertEqual of the calling function's self.
> But it seems too complicated. Is there a better approach?
> 
> You can see our code on GitHub:
> 
> master:
> https://github.com/speedy-net/speedy-net/blob/master/speedy/core/accounts/tests/test_factories.py
> 
> staging (under development):
> https://github.com/speedy-net/speedy-net/blob/staging/speedy/core/accounts/tests/test_factories.py

Hi,

The factory class is not really the place to put your test assertions.
That would be the responsibility of the code of your actual test
cases. Factories are just one of the tools that you happen to mostly
use in tests, but you can totally use them to generate a sample
database outside of an automated test environment.

Running this kind of test code in your factory would also have the
drawback that you'd run the same asserts over and over and over again
every single time you invoke the factory – which might be thousands of
times during one run of your test suite.

As I understand it, you want to test your factories, which is a good
idea. What I suggest you do is to just write a separate test module
for your factories.

Good luck,

Michal
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQIcBAEBCgAGBQJcPL0tAAoJEHA7T/IPM/klKeUQAMYUPpVVXAazNEt6Ga2He5V3
ZmmCDyYqQIJvrDAEwX7S1HbOq2K+EjvKeL2/dAf0Si7SQJPsjHcElUOIuSs+ch+/
46C5KM+3LLf3v2H6u1793TQy+oImoaygv8Mp3OZ8j7bfUH2dsBiLhECmfwQz48Ra
Uw/p7FoKKsT5saVK/bA4uoI2mIrnBKCj2KiZyYbkRs928tP9tAYIsHAotSXHDZVo
at8yyJ+J1nFFAzhZPJWN72zK0Pw5RdPF2L3wOrRhVgHLDfYsaZI9O4+6HYBjKkPn
6YWTVG1xq5p+dfofvtdzzFOiDn2rBRWgLlx3zl9cVE6xY7HjaieCI1a9IaePFXy8
MRIytt1Cc41tyT1lCl2yFBc+NT0+DFZMizNUkTgdzwM2uL2BlIh3+GsEY82ZzX/H
iwZ8DSOVuE2Iqpo132LrqcllHqNehxSYya7WBeBYHJiuDq2b2OaJp6ko5eb13ukn
LaVZGVwl+dmSx9HhVDqYHWHxK7AuEiE0CI+Y7Oy7RQhSH97L2MEw1qQlt6UxZtiz
83U0+RbNjDqXN0oMhswHtbnvnqnvKMg5zHVjzoLdAxrT+IIWUAnP6IqIM9v4UkgX
1aPof7eI6nm//ZA+fjmjCRorF3rHi98ZeK0a9Xccakl09zNKX7Vc/nlIbQqlKV8e
YawH4kZesUSUWBkIuIV/
=0T5r
-----END PGP SIGNATURE-----

-- 
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+unsubscr...@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/20190114164741.GV8269%40koniiiik.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to