lightly-ai/lightly

Migrate unittest.TestCase to pytest-style test classes

Aberta

#1.987 aberto em 22 de jul. de 2026

 (8 comentários) (0 reação) (0 responsável)Python (337 forks)auto 404
enhancementgood first issuehelp wanted

Métricas do repositório

Stars
 (3.775 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

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.

  • 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.

Guia do colaborador