-
Notifications
You must be signed in to change notification settings - Fork 7k
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 more tests files to pytest #4033
Comments
I'm working on |
Hey @NicolasHug, I will try working on |
Hi @NicolasHug !! I will work on |
Hey @NicolasHug, I will try working on |
I'll also pickup the only one left |
All done! Thank you so much everyone for the blazing fast PRs!! |
Now that we support
pytest
, we want to remove the use of theunittest
module for different test files. We've already ported a lot of tests in previous issues (#3987, #3945, #3956, #3951), and we want to extend this to more files now.Instructions
I listed the list of files that need to be ported below. If you're interested in working on this issue, please comment below with "I'm working on
file X
" so that others don't pick the same file as you do. To keep things simple, please only submit one PR per file, and don't pick more than 2 files at once. You can pick more files once your PRs are merged. Before picking a group, make sure it wasn't picked by another contributor first.Please don't hesitate to ask for guidance and help! Thanks!!
How to port a test to pytest
Porting a test from
unittest
to pytest is usually fairly straightforward. For a typical example, see https://github.com/pytorch/vision/pull/3907/files:Tester(unittest.TestCase)
class and just declare it as a function. Note: for some files, it might make sense to keep the class structure, and just rename the class as e.gTestBlahBlah:
@unittest.skipIf
withpytest.mark.skipif(cond, reason=...)
self.assertXYZ
.assertEqual(a, b)
can be replaced byassert a == b
when a and b are pure python objects (scalars, tuples, lists), and otherwise we can rely onassert_equal
ortorch.testing.assert_close
(look for other usage of these files in the codebase if needed)self.assertRaises
should be replaced with thepytest.raises(Exp, match=...):
context manager, as done in https://github.com/pytorch/vision/pull/3907/files. Same for warnings withpytest.warns
self.assertTrue
should be replaced with a plainassert
pytest.mark.parametrize
instead, as done e.g. in https://github.com/pytorch/vision/pull/3907/files.Files that need to be ported:
test_datasets_video_utils.py
Port test_datasets_video_utils.py to pytest #4035This one will be quite easy, you'll just need to rename the
Tester(unittest.TestCase) class into e.g. TestVideo, and change
with self.assertWarns(UserWarning):
intowith pytest.warns(UserWarning):
test_hub.py
Port test_hub.py to pytest #4038test_datasets_samplers.py
Port test_datasets_samplers.py to pytest #4037test_models_detection_anchor_utils.py
Port test_models_detection_anchor_utils.py to pytest #4046test_models_detection_negative_samples.py
Port test_models_detection_negative_samples.py to pytest #4045test_models_detection_utils.py
port test_models_detection_utils.py to pytest #4036test_onnx.py
Port test_onnx.py to pytest #4047test_transforms_video.py
Port tests in test_transforms_video.py to pytest #4040cc @pmeier
The text was updated successfully, but these errors were encountered: