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

Using pytest for integration tests. #4125

Merged

Conversation

prady0t
Copy link
Contributor

@prady0t prady0t commented Jun 2, 2024

Description

Running integration tests with pytest. Almost 50% of the integration tests were failing due to multiple tests accessing test_model.json file leading to race conditions and file corruption. We have used uuid to generate unique filename for every test. With this approach we can run all integration tests in parallel. Overall time to run integration tests is approx. 7-8 min. now

Addresses #3617

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.

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

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 $ python run-tests.py --quick (or $ 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

Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
@agriyakhetarpal
Copy link
Member

I merged develop (it looked like your branch is out of date) to trigger a CI run with caching and to try out with the tip of the trunk. The macOS ARM builds are generally faster, I hope we'll be able to see under 10-minute runs pretty soon

@agriyakhetarpal
Copy link
Member

This is looking very good for local development purposes, and would have been even better if we had larger GitHub runners. Here are the results from a few local runs from my macOS machine with 11 cores:

Running the integration tests via serial execution

$ python -m pytest tests/integration -n1

============================== 344 passed, 1 skipped in 563.97s (0:09:23) ==============================

Running the integration tests via parallel execution

$ python run-tests.py --integration

============================== 344 passed, 1 skipped in 100.53s (0:01:40) ==============================

From 0:09:23 to 0:01:40 – a massive boost 🎉 an ~82% reduction in test time, and a ~4.6x faster test suite.

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.

This looks great, thanks, @prady0t! As discussed, cleaning up the run-tests.py file will be great to look at in the coming weeks, there are a lot of if-else conditions in there. I did test out run-tests.py --unit and run-tests.py --integration along with their nox equivalents, and all of them are collecting the expected tests.

prady0t and others added 3 commits June 2, 2024 23:32
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
@prady0t
Copy link
Contributor Author

prady0t commented Jun 2, 2024

This looks great, thanks, @prady0t! As discussed, cleaning up the run-tests.py file will be great to look at in the coming weeks, there are a lot of if-else conditions in there. I did test out run-tests.py --unit and run-tests.py --integration along with their nox equivalents, and all of them are collecting the expected tests.

Are we planning to eventually completely remove run_test.py file?

@agriyakhetarpal
Copy link
Member

Are we planning to eventually completely remove run_test.py file?

Yes, it looks like there is a bunch of legacy, verbose code that is better replaced by keeping all of the testing commands/infra inside noxfile.py. We can use advanced features from Nox and improve the sessions to provide a similar experience, plus document the options better. Let's keep this plus testing the built wheels in mind for this week's discussions.

@agriyakhetarpal agriyakhetarpal merged commit 3086b4a into pybamm-team:develop Jun 2, 2024
24 checks passed
js1tr3 pushed a commit to js1tr3/PyBaMM that referenced this pull request Aug 12, 2024
Signed-off-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Co-authored-by: Pradyot Ranjan <99216956+pradyotRanjan@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com>
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.

2 participants