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
Currently, most tests in test/test_datasets_utils.py rely on unittest.TestCase. Now that we support pytest, we want to remove the use of the unittest module.
Instructions
Please comment below if you're interested to work on this and submit a PR for all the tests in this file.
Here are a few instructions specific to this file. I just gave it a brief look so I might be wrong on some of these, use your best jugement ;)
parametrize test_detect_file_type over (file, expected)
group all of test_detect_file_type_no_ext,
test_detect_file_type_to_many_exts,
test_detect_file_type_unknown_archive_type,
test_detect_file_type_unknown_compression,
test_detect_file_type_unknown_partial_ext, into a single test function
parametrized over the file name, and convert the function names as
comments to document the tests
test_decompress_gzip and test_decompress_lzma and
test_decompress_remove_finished can probably be bundled into the same test
function with some parametrization over the extension and over remove_finished
test_extract_archive_defer_to_decompress should be parametrized over ext and removed_finished (2 separate parametrizations)
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.
Currently, most tests in test/test_datasets_utils.py rely on
unittest.TestCase
. Now that we supportpytest
, we want to remove the use of theunittest
module.Instructions
Please comment below if you're interested to work on this and submit a PR for all the tests in this file.
Here are a few instructions specific to this file. I just gave it a brief look so I might be wrong on some of these, use your best jugement ;)
test_detect_file_type
over (file, expected)test_detect_file_type_to_many_exts,
test_detect_file_type_unknown_archive_type,
test_detect_file_type_unknown_compression,
test_detect_file_type_unknown_partial_ext, into a single test function
parametrized over the file name, and convert the function names as
comments to document the tests
test_decompress_remove_finished can probably be bundled into the same test
function with some parametrization over the extension and over
remove_finished
mocker
fixture as done in https://github.com/pytorch/vision/pull/4032/filesHow 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.cc @pmeier
The text was updated successfully, but these errors were encountered: