lightly-ai/lightly

Migrate unittest.TestCase to pytest-style test classes

開放

#1,987 建立於 2026年7月22日

 (8 則留言) (0 個反應) (0 位負責人)Python (337 個分叉)auto 404
enhancementgood first issuehelp wanted

倉庫指標

星標
 (3,775 顆星)
PR 合併指標
 (平均合併 8天) (30 天內合併 34 個 PR)

描述

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.

  • Coretests/core/test_Core.py
  • Datatests/data/test_LightlyDataset.py, tests/data/test_VideoDataset.py, tests/data/test_data_collate.py
  • Embeddingtests/embedding/test_embedding.py
  • Modelstests/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 modulestests/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
  • Transformstests/transforms/test_gaussian_blur.py, tests/transforms/test_jigsaw.py, tests/transforms/test_Solarize.py
  • Utilstests/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 fixture
  • self.assertEqual(a, b)assert a == b (same for assertTrue, assertListEqual, assertIsInstance, etc.)
  • @unittest.skipUnless(cond, msg)@pytest.mark.skipif(not cond, reason=msg)
  • Drop import unittest where no longer needed

No behavior change expected — tests should still pass identically after conversion.

貢獻者指南