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_ops.py to pytest #3953

Merged
merged 9 commits into from
Jun 4, 2021
Merged

Conversation

NicolasHug
Copy link
Member

This PR ports the entire test_ops.pyfile to pytest. It went pretty smoothly considering the size of the file, as the class structure already in place really helped.

The diff looks a bit big but it's mainly because I parametrized some methods, so the indentation of the (now removed) for loops isn't here anymore.

The rest is just adding a bunch of decorators and changing class names so that they're properly discovered by pytest

Comment on lines +20 to +22
@pytest.mark.parametrize('device', cpu_and_gpu())
@pytest.mark.parametrize('contiguous', (True, False))
def test_forward(self, device, contiguous, x_dtype=None, rois_dtype=None, **kwargs):
Copy link
Member Author

Choose a reason for hiding this comment

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

The previously manual cross-product between device and contiguous is now seamlessly handled by the parametrization, both for test_forward and test_backward

@NicolasHug
Copy link
Member Author

Perhaps @datumbox or @pmeier are available for a review :) ?

Copy link
Collaborator

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

Looking good @NicolasHug. Two comments:

  • Can we declare RoIOpTester an abc.ABC and mark the abstract methods as such? Makes it easier to read and catches errors faster if we need to add a new test case.
  • Can the _test_boxes_shape merged into the base class with the same pattern as the other tests?

test/test_ops.py Outdated Show resolved Hide resolved
test/test_ops.py Outdated Show resolved Hide resolved
@NicolasHug
Copy link
Member Author

Thanks for the review @pmeier ! Your comments were addressed :)

_test_boxes_shape merged into the base class with the same pattern as the other tests?

Yeah it was a bit weird. I just kept def _helper_boxes_shape(self, func): in the base class and declared test functions in the child classes as

    @cpu_only
    def test_boxes_shape(self):
        self._helper_boxes_shape(ops.roi_pool)

Copy link
Collaborator

@pmeier pmeier left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @NicolasHug!

@NicolasHug NicolasHug merged commit a0cd96f into pytorch:master Jun 4, 2021
facebook-github-bot pushed a commit that referenced this pull request Jun 10, 2021
Reviewed By: NicolasHug

Differential Revision: D29027309

fbshipit-source-id: 7704b4e86a7f476f405a981112b73677d0bff16c
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.

3 participants