lightly-ai / lightly-ai/lightly
Migrate unittest.TestCase to pytest-style test classes
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 3.8k
- Forks
- 367
- Avg merge
- 3d 22h
- Merged PRs (30d)
- 5
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 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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by choosing one listed group and compare its files with the pytest-style pattern in tests/loss/test_ibot_loss.py. Convert only that group’s unittest.TestCase usage, fixtures, assertions, skips, and imports, then run the group’s tests. Done means the selected tests pass identically without the old unittest patterns.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 75/100