-
Notifications
You must be signed in to change notification settings - Fork 75
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
Refactor web_api test using pytest.fixtures #984
Conversation
a8c2d3a
to
a01c3d5
Compare
UpdateUpon @cesco-fran 's recommendation (thanks!) I have updated the scope for the 'test_tax_benefit_system' fixture to "module". This balances runtime (so we don't have to initialise a new tax-benefit-system for every test), with error potential due to tax-benefit-systems being mutable. I think this PR is in any case an improvement on the current state, which mutates the TaxBenefitSystem object from the openfisca_country_template. |
Thanks a lot @RamParameswaran ! Looks good. Regarding context:
I think the idea behind the current situation is to have integration testing be done against a lively source of real-world examples and scenarios that, by the dependency between both, has to be always up to date - maintaining two different sets of templates proved burdensome, but keeping the current situation seems impossible also due to next changes to the dependencies ecosystem. It would be great to have more comments and insight from the community to see what's the best route to go. I'll mark this contribution as RFC and follow it closely. 😃 |
Thanks @RamParameswaran for this contribution and thanks @maukoquiroga for the initial reply! 😃
Indeed, I decided back in 2017 to rely on the Country Template for testing, which resulted in #507, to solve two problems at once: (i) the lack of maintenance of the Country Template, (ii) the lack of integration tests in Core. No matter how much testing we did on Core, there were always breaks in production which could only be caught once Core was loaded in a full model environment; on the other hand, the Country Template is only a burden for maintainers unless it is part of their standard testing procedure. I appreciate how this PR improves software testing quality by ensuring fixtures are maintained in the same place as expected results are declared —this would have avoided #980, for example 🙂 I would thus be in favour of merging this if dedicated integration tests, probably still relying on the Country Template, are also added to the testing procedure 🙂 |
Thanks for your reply @MattiSG :) I should note that the circular dependency on the Country Template also makes is very difficult to write functional tests for new features. An example is #983. In order to write functional tests for #983, we must: i) merge #983, ii) add the necessary test data to Country Template, iii) create a new PR with functional tests for #983. However, I completely understand your point about the necessity to maintain the Country Template. For this purpose I support having dedicated integration tests in of-core. Regarding the issues found in #990 - pip dependency resolution is a mystery to me so I can't really comment 😅 |
Hi @RamParameswaran ! You can actually install from Github like this in order to test:
But yes it is definitely not ideal. I think a first move towards a solution would be to clearly separate unit, functional and integration tests, and keep country template's scenarios for testing only de latter. I'm taking a look at both this PR and #969 to come up with an RFC. |
- this minimal TaxBenefitSystem has the same Entities as the `openfisca_country_template` - it one mock Parameter and one mock Variable
- In this fixture you can instantiate the variables that will be needed by your tests, add them to the TaxBenefitSystem, and create an App Client
…e objects for every single test
… "openfisca_country_template"
…dule". Thanks @cesco-fran for the recommendation!
…ariable_formula_content`
…_.py" since we now use the fixtures defined in "tests/fixtures"
90ba91d
to
aa3157c
Compare
Hi all. I have updated this PR to align with #997.
@MattiSG to address your above concerns, this PR no longer aims to reduce the dependence on Country-Template. Instead it simply modularises the web_api test suite so it uses the pytest fixtures defined in "test/fixtures/". These fixtures themselves are created from the Country-Template 👌 As always, happy to hear your thoughts! 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✨ thanks @RamParameswaran ! Just the minor comment above on the underscore in the client argument otherwise LGTM 💯
Context
of-core
should exist inof-core
...!Technical changes
TaxBenefitSystem
fixture inconftest.py
. This is a minimal TBS. The intent is that variables and parameters are added within test modules as needed. This keeps test data and test functions in the same location ✔️test_client
fixture in which we instantiate the variables we need for our tests ✔️test_variables.py
to use thetest_client
fixture instead ✔️Further steps
test/web_api/test_variables.py
module. To decouple all 'web_api' tests from theopenfisca_country_template
package, we need to also refactortest_calculate.py
,test_entities.py
,test_spec.py
andtest_trace.py
.Notes
Let me know your thoughts!
Thanks ✌️