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

[16.0][REF][l10n_br_base][l10n_br_fiscal][l10n_br_account] tests don't depend on demo #3563

Draft
wants to merge 8 commits into
base: 16.0
Choose a base branch
from

Conversation

rvalyi
Copy link
Member

@rvalyi rvalyi commented Dec 28, 2024

both Odoo SA [1] and the OCA [2][3] recommend that tests don't depend on demo data. Here I'm starting this cleanup on the most central modules. Benefits include:

  • the test context is simpler and easier to figure out
  • this avoids the demo data incompatibility hell where arbitrary modules alter demo data and depending on what modules are installed exactly your tests may fail with no clear explanation
  • this allows to run fiscal tests on copy of production databases

We have long wished to achieve that in the project. However, in l10n-brazil we need to maintain both complex fiscal demo data and fiscal test fixtures. That is why until now the test fiscal transactions where based on demo data.

In this PR, I created a simple framework (with l10n_br_base/tests/tools.py and l10n_br_fiscal/tests/tools.py) where we can load the SAME fiscal demo data both for the demo mode and for the tests even on databases created without demo data (like with the --without-demo=all param). I had to clean up a bit useless relations to demo data in the fiscal demo data and work around the demo data of the product module.

As we tend to reload the same fiscal demo fixtures in several tests, tests are a bit slower. But:

  • in the future they could actually be faster if we create test databases with --without-demo=all
  • it's v16 which is 3x faster than v14, so not such a big deal (only a few dozens of extra seconds)
  • even if tests do a bit more queries, they are much easier and faster to debug this way...

Finally, let me remind you that we cannot simply use the production set up for the Brazilian tax engine both for demo and tests because unlike for European countries, the Brazilian tax engine setup requires loading several MB of XML and csv files which easily take 3 minutes of heavy CPU usage and that would be a terrible developper experience to eat it for any quick test or CI push. (At the moment the decision to load production data or not happens in l10n_br_fiscal/hooks.py)

NOTE1: also see work in progress for l10n_br_sale module (some tests still failing) akretion@9667018 (in fact it seems my local test with --without-demo=all failed because of discrepancies between the demo and prod NCM data. See next note.

NOTE2: this PR will also work best in conjunction with the refactor of #3567 to standardize the data and demo files loading. Once #3567 is merged we will get rid of the demo NCM and CEST files so the load of the test fixtures will be much faster!

@rvalyi rvalyi marked this pull request as draft December 28, 2024 02:45
@rvalyi rvalyi changed the title [REF] l10n_br_base: tests don't depend on demo [16.0][REF] l10n_br_base: tests don't depend on demo Dec 28, 2024
@rvalyi rvalyi changed the title [16.0][REF] l10n_br_base: tests don't depend on demo [16.0][REF][l10n_br_base][l10n_br_fiscal][l10n_br_account] tests don't depend on demo Dec 28, 2024
@rvalyi rvalyi force-pushed the 16.0-test-no-demo branch 5 times, most recently from 88cca3c to a2d95aa Compare December 28, 2024 03:24
@OCA-git-bot
Copy link
Contributor

Hi @renatonlima,
some modules you are maintaining are being modified, check this out!

@rvalyi rvalyi force-pushed the 16.0-test-no-demo branch 4 times, most recently from cc8d418 to 254895b Compare December 28, 2024 21:02
@rvalyi rvalyi force-pushed the 16.0-test-no-demo branch 2 times, most recently from 7989057 to 55ce21f Compare December 29, 2024 01:36
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

Successfully merging this pull request may close these issues.

3 participants