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

Use plain asserts in tests #1448

Merged
merged 4 commits into from
Feb 14, 2024
Merged

Conversation

akx
Copy link
Contributor

@akx akx commented Feb 7, 2024

Plain assertions are easier to debug than Unittest self.assert*s due to Pytest's assertion rewriting.

Similar to huggingface/accelerate#2420, this was done via codemod-unittest-to-pytest-asserts and ast-grep.

Sibling of huggingface/trl#1301.

@akx akx changed the title Use plain asserts Use plain asserts in tests Feb 7, 2024
@BenjaminBossan
Copy link
Member

As Zach mentioned, we'll have an internal discussion first to ensure that we have consensus, as we want the HF code bases to be consistent when it comes to the testing style (we know they're not completely consistent right now, but mostly).

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@BenjaminBossan
Copy link
Member

Could you please run make style again?

@akx
Copy link
Contributor Author

akx commented Feb 14, 2024

@BenjaminBossan Rebased, reformatted.

@BenjaminBossan
Copy link
Member

@akx There are some instances of pytest.raises(warning, ...) which currently fail. Using pytest.warns(warning, ...) should work though.

@akx akx force-pushed the codemod-pytest branch 5 times, most recently from 813fc25 to 861566e Compare February 14, 2024 13:04
@akx akx force-pushed the codemod-pytest branch 2 times, most recently from 9ec3e07 to 1003c39 Compare February 14, 2024 14:38
Copy link
Member

@BenjaminBossan BenjaminBossan 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 all the work, this is much better on the eye!

@BenjaminBossan BenjaminBossan merged commit 5f20846 into huggingface:main Feb 14, 2024
14 checks passed
BenjaminBossan pushed a commit to BenjaminBossan/peft that referenced this pull request Mar 14, 2024
Use pytest style asserts instead of unittest methods.

Use `pytest.raises` and `pytest.warns` where suitable.
BenjaminBossan pushed a commit to BenjaminBossan/peft that referenced this pull request Mar 14, 2024
Use pytest style asserts instead of unittest methods.

Use `pytest.raises` and `pytest.warns` where suitable.
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