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

Port test/test_datasets.py to use pytest #4215

Merged
merged 4 commits into from
Jul 28, 2021
Merged

Port test/test_datasets.py to use pytest #4215

merged 4 commits into from
Jul 28, 2021

Conversation

yiwen-song
Copy link
Contributor

@yiwen-song yiwen-song commented Jul 28, 2021

Following the discussion in #3945, we should also port test/test_dataset to use pytest.

In this PR, we replace all the self.assertXYZ with python assert.

TODO: Replace the self.subTest() in these files and finally remove the unittest.TestCase inheritance.

Copy link
Member

@NicolasHug NicolasHug left a comment

Choose a reason for hiding this comment

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

Thanks @sallysyw , contrags on your first torchvision PR!
This looks great, there are just 2 assertions that need a minor change. I'll approve anyway, feel free to self-merge once the changes are addressed

@NicolasHug
Copy link
Member

Indeed the next step will be to fully remove the use of unittest.TestCase and thus remove the subTest parts, which I think is fine.

It'd be nice to change the test_all_configs decorator into a pytest parametrization. @pmeier do you foresee any major complication in doing that?

@yiwen-song yiwen-song merged commit b29ed34 into pytorch:master Jul 28, 2021
@yiwen-song yiwen-song deleted the develop branch July 28, 2021 22:58
@github-actions
Copy link

Hey @sallysyw!

You merged this PR, but no labels were added.

@pmeier
Copy link
Collaborator

pmeier commented Jul 29, 2021

It'd be nice to change the test_all_configs decorator into a pytest parametrization. @pmeier do you foresee any major complication in doing that?

IIRC, you can't use pytest.mark.parametrize on the test methods of a unittest.TestCase. So we would also need to change that class. But then, we are currently using the TestCase.setUpClass method

@classmethod
def setUpClass(cls):
cls._verify_required_public_class_attributes()
cls._populate_private_class_attributes()
cls._process_optional_public_class_attributes()
super().setUpClass()

which we would have to emulate another way.

@NicolasHug
Copy link
Member

IIRC, you can't use pytest.mark.parametrize on the test methods of a unittest.TestCase

That's correct, and getting rid of unittest altogether is our end goal here :). Regarding the setup, we'll probably just have to rename it into a setup_class method instead: https://docs.pytest.org/en/6.2.x/xunit_setup.html#class-level-setup-teardown

facebook-github-bot pushed a commit that referenced this pull request Aug 3, 2021
Summary:
* Port test_datasets.py to use pytest

* A better replacement of self.assertSequenceEqual

* Migrate from equality check to identity check

Reviewed By: NicolasHug

Differential Revision: D30069955

fbshipit-source-id: 0f86c15f1457d1bcf21a4c634b0a70e256a804f5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants