Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: use pytest fixtures to parameterize tests for lead acid battery model #4723

Merged
merged 9 commits into from
Feb 22, 2025

Conversation

Aswinr24
Copy link
Contributor

Description

Refactored the lead-acid model test cases to use pytest fixtures, reducing code duplication and improving test clarity and maintainability.

Related to #4502

Type of change

Please add a line in the relevant section of CHANGELOG.md to document the change (include PR #) - note reverse order of PR #s. If necessary, also add to the list of breaking changes.

  • Code refactor (test improvements to reduce repetition)

Key checklist:

  • No style issues: $ pre-commit run (or $ nox -s pre-commit) (see CONTRIBUTING.md for how to set this up to run automatically when committing locally, in just two lines of code)
  • All tests pass: $ python run-tests.py --all (or $ nox -s tests)
  • The documentation builds: $ python run-tests.py --doctest (or $ nox -s doctests)

You can run integration tests, unit tests, and doctests together at once, using $ nox -s quick.

Further checks:

  • Code is commented, particularly in hard-to-understand areas
  • Tests added that prove fix is effective or that feature works

Copy link

codecov bot commented Dec 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.70%. Comparing base (651584f) to head (8205a6f).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4723   +/-   ##
========================================
  Coverage    98.70%   98.70%           
========================================
  Files          304      304           
  Lines        23452    23452           
========================================
  Hits         23149    23149           
  Misses         303      303           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't gone through the tests in detail, just skimmed them for now – I think this looks wrong because tests for options such as {"current collector": "potential pair", "dimensionality": 1} that were previously present have been removed, apparently. The tests for the lumped thermal model are not present either (and others). Is this PR ready for review, @Aswinr24, or is it in progress and you're writing more tests? Apologies if it's the latter (and please mark it as a draft if it is!)

@Aswinr24 Aswinr24 marked this pull request as draft December 30, 2024 16:26
@prady0t
Copy link
Contributor

prady0t commented Dec 31, 2024

@Aswinr24 Thanks for adding fixtures across tests! I suggest covering multiple files per PR so we don't have too many PRs covering single files. While you are working with this file, try to find more tests that can be parameterized using fixtures and cover those in this PR as well.

Once you have enough tests, you can mark this for review. Also, make a list of files (for yourself, no need to open any tracking issue) to keep track of the files you went through and the ones that are pending.

I'll add my reviews once it's marked as ready.

@Aswinr24
Copy link
Contributor Author

Thanks for the feedback @prady0t @agriyakhetarpal !
Sure will try adding multiple files in this PR and cover the tests that I believe can be parameterized using fixtures

@Aswinr24
Copy link
Contributor Author

Aswinr24 commented Jan 4, 2025

@prady0t @agriyakhetarpal Could You Please Review this.
I have tried to cover most of the tests which can be parameterized using fixtures, particularly in case of the Lead Acid Battery Model.
Would like to hear your feedback on this

@Aswinr24 Aswinr24 marked this pull request as ready for review January 4, 2025 09:53
@Aswinr24 Aswinr24 changed the title refactor: use pytest fixtures to reduce repetition in tests refactor: use pytest fixtures to parameterize tests for lead acid battery model Jan 4, 2025
Copy link
Contributor

@prady0t prady0t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just by looking at the changes, I think we can use parametrize fixture here. @Aswinr24 can you maybe look into ways you can parametrize these tests?
Before that please add the class structure back, it would be easier to review with a cleaner diff.

@Aswinr24
Copy link
Contributor Author

Aswinr24 commented Jan 5, 2025

@prady0t Thanks for the review, added back the class structure and tried to use the parameterize fixture wherever feasible.
Could you check this now

@prady0t
Copy link
Contributor

prady0t commented Jan 7, 2025

It looks good. The tests look clean! The CI failure is unrelated to this PR, as the tests pass locally for me. Maybe we should re-run. @agriyakhetarpal would love your thoughts on these changes.

@Aswinr24
Copy link
Contributor Author

@agriyakhetarpal could you please review this submission and check if it is good to go?
Waiting to hear your thoughts on the changes done

@agriyakhetarpal
Copy link
Member

Hi @Aswinr24, thanks for your work! I haven't had time to look at these changes in detail, sorry for the delay on this. I'll try to do so this weekend.

Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up, @Aswinr24! Sorry for the delay in review. See my comments below -

Comment on lines 7 to 9
@pytest.fixture
def loqs_model():
return pybamm.lead_acid.LOQS()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a redundant refactor (plus pass-by-sharing might meddle with the tests here), so I would suggest initialising the model in each test (just how it is done right now).

@Saransh-cpp
Copy link
Member

Could you also resolve the conflicts? Thanks!

@Saransh-cpp Saransh-cpp marked this pull request as draft February 13, 2025 00:16
@Aswinr24
Copy link
Contributor Author

Thanks for the review!
Sure will get back to you once I am done with resolving the conflicts and the changes suggested @Saransh-cpp

@Aswinr24
Copy link
Contributor Author

@Saransh-cpp done with my changes needed and resolving conflicts, waiting to hear if it is good to go ?

Saransh-cpp
Saransh-cpp previously approved these changes Feb 19, 2025
Copy link
Member

@Saransh-cpp Saransh-cpp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @Aswinr24! This looks good to me. I will wait for a review by others before merging this.

@Saransh-cpp Saransh-cpp requested a review from prady0t February 19, 2025 10:55
@Saransh-cpp Saransh-cpp marked this pull request as ready for review February 19, 2025 10:55
@Saransh-cpp Saransh-cpp requested a review from a team as a code owner February 19, 2025 10:55
Copy link
Contributor

@prady0t prady0t left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm. Thanks @Aswinr24!

Copy link
Member

@agriyakhetarpal agriyakhetarpal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @Aswinr24! I have a couple of small suggestions, happy to approve after.

@Aswinr24
Copy link
Contributor Author

@agriyakhetarpal Done with my changes! waiting to hear if it is good to go ?

@agriyakhetarpal
Copy link
Member

This is good to go, indeed. Thanks, @Aswinr24!

@agriyakhetarpal agriyakhetarpal enabled auto-merge (squash) February 22, 2025 21:39
@agriyakhetarpal agriyakhetarpal merged commit 725a42c into pybamm-team:develop Feb 22, 2025
25 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants