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

[WIP] Change tests to pytest format. #639

Merged
merged 6 commits into from
Nov 16, 2022

Conversation

tillahoffmann
Copy link
Contributor

@tillahoffmann tillahoffmann commented Nov 15, 2022

Submission Checklist

  • Run unit tests
  • Declare copyright holder and open-source license: see below

Summary

This PR changes the test suite from unittest.TestCase format to pytest. This should, for example, allow the use of fixtures and @parametrize decorators. To minimize the risk of this change breaking anything, it only touches files in the test folder. There are a lot of changes, but they are mostly trivial.

Some specific changes:

  • Used assert statements to replace self.assert* from the unittest.TestCase.
  • Used np.testing.* wherever the previous code used self.assertTrue(np.*).
  • Replaced nested calls in tests (e.g., to run with different stan_files) to use @parameterize decorators.
  • Removed custom environment variable modifier and instead used unittest.mock.patch.dict.
  • Replaced testfixtures.LogCapture with pytest's caplog fixture.
  • Replaced replace_stdin by unittest.mock.patch.

It looks like other tests could benefit from using @parameterize decorators, but I've left them unchanged here to avoid changing both framework and logic. Changes and suggestions welcome on this work in progress.

Copyright and Licensing

Please list the copyright holder for the work you are submitting (this will be you or your assignee, such as a university or company): Harvard University

By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:

@codecov-commenter
Copy link

codecov-commenter commented Nov 15, 2022

Codecov Report

Merging #639 (04e6c4d) into develop (c4c6bb7) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff            @@
##           develop     #639   +/-   ##
========================================
  Coverage    80.13%   80.13%           
========================================
  Files           69       69           
  Lines        10335    10335           
========================================
  Hits          8282     8282           
  Misses        2053     2053           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Copy link
Member

@WardBrian WardBrian 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 doing this! A few small comments before I download and run them myself. Did you do this in any sort of automated way?

@tillahoffmann
Copy link
Contributor Author

Did you do this in any sort of automated way?

Mostly a bit of regex matching and replacement with some manual fixes where it failed.

@WardBrian
Copy link
Member

I noticed tests passed, do you think this is ready for a more thorough review?

@tillahoffmann
Copy link
Contributor Author

Yes, I think this is ready for a more thorough review. Thank you for looking into it.

Copy link
Member

@WardBrian WardBrian left a comment

Choose a reason for hiding this comment

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

Thanks a ton for cleaning all this up!

@WardBrian WardBrian merged commit d5ed366 into stan-dev:develop Nov 16, 2022
@tillahoffmann tillahoffmann deleted the pytest branch November 16, 2022 21:41
@WardBrian WardBrian mentioned this pull request Jan 10, 2023
@tillahoffmann tillahoffmann mentioned this pull request Feb 13, 2023
2 tasks
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