You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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"
take the test method out of the Tester(unittest.TestCase) class and just declare it as a function
Replace @unittest.skipIf with pytest.mark.skipif(cond, reason=...)
remove any use of self.assertXYZ.
Typically assertEqual(a, b) can be replaced by assert a == b when a and b are pure python objects (scalars, tuples, lists), and otherwise we can rely on assert_equal which is already used in the file.
self.assertTrue should be replaced with a plain assert
When a function uses for loops to tests multiple parameter values, one should usepytest.mark.parametrize instead, as done e.g. in https://github.com/pytorch/vision/pull/3907/files. From a quick look, I don't think this will be needed for the tests in test_utils.py
The text was updated successfully, but these errors were encountered:
Currently, most tests in test/test_utils.py rely on
unittest.TestCase
. Now that we supportpytest
, we want to remove the use of theunittest
module.Similar issues: #3915, #3914
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:Tester(unittest.TestCase)
class and just declare it as a function@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
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
pytest.mark.parametrize
instead, as done e.g. in https://github.com/pytorch/vision/pull/3907/files. From a quick look, I don't think this will be needed for the tests intest_utils.py
The text was updated successfully, but these errors were encountered: