PyBaMM icon indicating copy to clipboard operation
PyBaMM copied to clipboard

chore: enable pytest ruff rule and apply fixes

Open Aswinr24 opened this issue 11 months ago • 6 comments

Description

This PR enables additional Ruff linting rules and applies fixes to the codebase as suggested by Ruff. The changes include:

Enabling PT (pytest-style) rules in pyproject.toml.

fixes issues raised by ruff linter which included:

  • PT006: Update @pytest.mark.parametrize to use a tuple for multiple parameters instead of a list or comma-separated strings.
  • PT011: Ensure pytest.raises() is called with a match parameter to avoid catching overly broad exceptions.
  • PT012: Ensure pytest.raises() context managers contains only a single statement.

Related to #4925

Type of change

  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Optimization (back-end change that speeds up the code)
  • [x] Bug fix (non-breaking change which fixes an issue)

Key checklist:

  • [X] 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)
  • [x] All tests pass: $ python -m pytest (or $ nox -s tests)
  • [ ] The documentation builds: $ python -m pytest --doctest-plus src (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
  • [x] Tests added that prove fix is effective or that feature works

Aswinr24 avatar Mar 23 '25 14:03 Aswinr24

Yes thanks!, would resolve the conflicts and push it

Aswinr24 avatar Apr 25 '25 04:04 Aswinr24

Was thinking to open the PR to enable isort rule along with its suggested fixes as well
Though it does suggest changes in a lot of files, most of them are at the top of the files which shouldn't cause any issues, Do you suggest to go ahead with this @Saransh-cpp ?

Aswinr24 avatar Apr 25 '25 05:04 Aswinr24

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.58%. Comparing base (54f6e21) to head (5dc454b).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4928   +/-   ##
========================================
  Coverage    98.58%   98.58%           
========================================
  Files          304      304           
  Lines        23689    23689           
========================================
  Hits         23353    23353           
  Misses         336      336           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Apr 25 '25 07:04 codecov[bot]

Do you suggest to go ahead with this

Yes, sounds good to me.

Saransh-cpp avatar Apr 25 '25 08:04 Saransh-cpp

pre-commit.ci run

Saransh-cpp avatar Apr 27 '25 15:04 Saransh-cpp

Thanks!

Aswinr24 avatar Apr 28 '25 18:04 Aswinr24