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 合并指标
 (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.

贡献者指南