-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Closed
Description
Currently, most tests in test/test_image.py rely on unittest.TestCase
. Now that we support pytest
, we want to remove the use of the unittest
module.
Instructions
If you're interested in working on this issue, please comment below with "I'm working on <test_method_a>, <test_method_b>, etc..." so that others don't pick the same tests as you do. The tests in this file are fairly easy to port, so it's possible to port all of them at once in a single PR, in which case please say "I'm working on porting all the tests"
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:
- take the test method out of the
Tester(unittest.TestCase)
class and just declare it as a function - Replace
@unittest.skipIf
withpytest.mark.skipif(cond, reason=...)
- remove any use of
self.assertXYZ
.- Typically
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
which is already used in the file. 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
- Typically
- When a function uses for loops to tests multiple parameter values, one should use
pytest.mark.parametrize
instead, as done e.g. in https://github.com/pytorch/vision/pull/3907/files. Typically here intest_image.py
, these will be things likefor pil_mode, mode in conversion:
, etc.