Contributors mailing list archives

contributors@odoo-community.org

Browse archives

Avatar

Re: demo data and tests

by
j_j_b_o_devel
- 18/12/2024 15:11:56

Hello,

On my projects I try to use demo data for master data, for the following reasons:

  • It results in code that is more readable.
  • I disagree that creating object in the fixture makes it easier to ensure tests are simple. It's much simpler to include a «self.data_name = self.env.ref("")» statement in the fixture that to include a full create({}) call, which often requires the programmer to specify fields that have nothing to do with the features being tested (like the object's name, etc).
  • Simple code make it easier to avoid creating a common setUpClass() method for every testcase in a module, which WILL have unintended consequences when you need to test some novel codepath that depends on some flags.
  • Small setup differences that a testcase may need can be encoded in instructions following the «self.data_name = self.env.ref("")» statement, like this:
    • self.bank_journal_01 = self.env.ref("account_bugfixes.demo_bank_journal_01")
    • self.bank_journal_01.code = "MYCODE01"
  • Makes it easier to compare fixtures used in unrelated tests, seeing in what they defer, etc.
  • I disagree that not depending on demo data makes it easier to ensure tests will run no matter how demo data might be touched by other modules. Invariants about fixture, in my opinion, must be enforced by including additional tests that assert that the test data begins as expected. Also, it's a design principle that new modules must not break existing functionality, and so must happen for demo data (i.e. in general, one should avoid patching existing demo records in dependencies).
  • Tests that depend on demo data also run faster, because demo data is created only once.

This is my opinion.

João Jerónimo


Às 15:52 de 12/12/2024, Raphaël Valyi escreveu:
Hello Odoo community,

More and more the OCA contributors avoid writing tests which depend on demo data and so does Odoo SA. This makes it easier to ensure tests are simple and will run no matter how demo data might be touched by other modules.

But eventually this could bring other benefits such as the ability to run these standard tests in the CI with production database dumps (that is where the demo data cannot be loaded in general).

In this case, I have a first question: probably some customization's might add required fields. What would be the best practice to be able to run these "native" or OCA tests that might fail to create records with such new constraints? We could imagine some monkey patches and standard hooks to help... We kind of face this already today by running tests with all repo modules installed, but with production dumps, much more modules would be installed together along with some non OCA customization which also need to be developed more cheaply...

But more important is my second question: if we set it as a good practice that OCA tests shouldn't depend on demo data, why are we still running the OCA CI with demo data enabled (still the case with Odoo 18 CI) ? Or is it planned we stop doing this in Odoo 19? I mean we could also save a good deal of server resources/time by not loading the gazillions of catchy Odoo CE demo data in each test run...


Thank you very much for your answers.


--
Raphaël Valyi
Founder and consultant

_______________________________________________
Mailing-List: https://odoo-community.org/groups/contributors-15
Post to: mailto:contributors@odoo-community.org
Unsubscribe: https://odoo-community.org/groups?unsubscribe

Reference