On Tuesday 21 February 2017 19:00:42 'Tom Evans' via Django users wrote:
> Previously, these instances were loaded from a JSON fixtures file,
And you can still do that.
> which used to be the recommended way. For our own tests, we simply
> load these fixtures in the setUp portion of the test; obviously we
> can't go around modifying tests in third party libraries.
> I tried taking them out of the fixtures, and adding them instead in a
> data migration, but this also had the same effect - the instances were
> there for the first test ran, and then missing for all the subsequent
> ones.
setUp is run between test methods of a test case. setupTestData is a class method on the testcase run once per test case.
>
>
> What is the "correct" way of ensuring that these instances exist in
> the test database before any test is run?
All explained in the docs.
Either redeclare the same fixtures for different test cases or reorganize your testcases to share the same fixture(s).
--
Melvyn Sopacua
-- Adam (ad...@csh.rit.edu)
On Wednesday 22 February 2017 14:22:36 'Tom Evans' via Django users wrote:
> On Wed, Feb 22, 2017 at 12:47 AM, Melvyn Sopacua <m.r.s...@gmail.com> wrote:
> > On Tuesday 21 February 2017 19:00:42 'Tom Evans' via Django users wrote:
> >> What is the "correct" way of ensuring that these instances exist in
> >>
> >> the test database before any test is run?
> >
> > All explained in the docs.
> >
> > Either redeclare the same fixtures for different test cases or
> > reorganize your testcases to share the same fixture(s).
>
> I think you have misunderstood:
>
> 1) The test cases belong to a library and cannot be modified
So don't use them as is or prompt the authors to update to the new way of things. In transition, you can extend the test cases and simply add a fixture attribute.
> 2) The initial data is populated from a data migration and not from a
> fixture, as that is not recommended [1]
Data migrations for the project are never relevant for tests, since the test database is empty. You're putting a label on "fixtures" that is only relevant for the provided context. Fixtures are not deprecated, not bad for you and do not mess up your aura.
On one hand It is as Adam says:
" It would seem to me that the docs are telling you to use fixtures for tests and use migrations for real data."
Adding to that - fixtures are still a solid way to load application data - only the use of "initial" or "autloaded" data is discouraged.
Fixtures should be used on production databases to selectively provide data, so that the user of the application can load "google_shopping.json" if it wants to publish it's products Google Shopping or not load it, if she doesn't.
--
Melvyn Sopacua
Cheers Tom
-- Adam (ad...@csh.rit.edu)
On Wednesday 22 February 2017 15:13:47 'Tom Evans' via Django users wrote:
> These tests exercise parts of django_otp that interact with parts of
> my code. Successful tests indicate that those two parts interoperate
> correctly. The tests are successful when run individually, but fail
> when run as a suite because data loaded as part of a migration is
> flushed away before the second test.
So they're different tests: they make use of the logic of the library's test suite, but operate on your data. Schoolbook example for inheritance:
from django_otp.tests import SuperTest
class SuperTestWithMyData(SuperTest):
fixtures = ['my_data']
--
Melvyn Sopacua