Migrate unittest.TestCase to pytest-style test classes
#1,987 opened on Jul 22, 2026
Repository metrics
- Stars
- (3,775 stars)
- PR merge metrics
- (PR metrics pending)
Description
Several test files still use unittest.TestCase from before we adopted pytest. New tests are plain pytest-style classes (see tests/loss/test_ibot_loss.py for the pattern: no TestCase base, assert instead of self.assertEqual/self.assertTrue, pytest.mark.parametrize instead of manual test variants, pytest.mark.skipif instead of unittest.skipUnless). This migrates the rest.
Excluded from this issue: files being deleted by #1939 (API client removal) — tests/api/test_BitMask.py, tests/api/test_rest_parser.py, tests/api/test_utils.py, tests/api_workflow/mocked_api_workflow_client.py, tests/api_workflow/test_api_workflow_client.py. No point migrating tests that are about to disappear.
Split into one PR per group below — comment to claim a group, don't mix groups in one PR.
- Core —
tests/core/test_Core.py - Data —
tests/data/test_LightlyDataset.py,tests/data/test_VideoDataset.py,tests/data/test_data_collate.py - Embedding —
tests/embedding/test_embedding.py - Models —
tests/models/test_ModelsBYOL.py,tests/models/test_ModelsMoCo.py,tests/models/test_ModelsNNCLR.py,tests/models/test_ModelsSimCLR.py,tests/models/test_ModelsSimSiam.py,tests/models/test_ModelUtils.py,tests/models/test_ProjectionHeads.py - Model modules —
tests/models/modules/test_ijepa_timm.py,tests/models/modules/test_masked_autoencoder.py,tests/models/modules/test_masked_autoencoder_timm.py,tests/models/modules/test_memory_bank.py - Transforms —
tests/transforms/test_gaussian_blur.py,tests/transforms/test_jigsaw.py,tests/transforms/test_Solarize.py - Utils —
tests/utils/test_debug.py,tests/utils/test_dist.py,tests/utils/test_io.py,tests/utils/test_version_compare.py
Mechanical conversion per file:
class Foo(unittest.TestCase):→class Foo:setUp/tearDown→ pytest fixtureself.assertEqual(a, b)→assert a == b(same forassertTrue,assertListEqual,assertIsInstance, etc.)@unittest.skipUnless(cond, msg)→@pytest.mark.skipif(not cond, reason=msg)- Drop
import unittestwhere no longer needed
No behavior change expected — tests should still pass identically after conversion.