Convert unittest-style tests to pytest and drop the PT exemptions

Open
#146 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Tech stack
django, python
Domain
testing

Research direction

Start with the per-file-ignores table in pyproject.toml to see which test files are exempt from the PT rules, then pick one small file such as config/tests/test_database_url.py and rewrite its TestCase methods as plain functions using assert and pytest.raises. Run uv run ruff check . and uv run pytest on that file. Leave the unittest-style probe string in config/tests/test_parallel_spawn.py as it is, since manage.py test needs it. Done means the file's exemption is removed, coverage is unchanged, and both commands pass.

Written by the indexing model from the issue text.

Description

area:infra priority:p2 size:M type:chore

The contributing guide says to write tests with pytest and plain assert. Ruff's pytest-style rules (PT, including PT009 and PT027) now check that, but 16 older test files are exempt through per-file-ignores in pyproject.toml because they still subclass Django's TestCase or SimpleTestCase and use self.assert* and assertRaises.

Files:

  • apps/accounts/tests/test_admin.py
  • apps/accounts/tests/test_ascii_policy.py
  • apps/accounts/tests/test_createsuperuser.py
  • apps/accounts/tests/test_models.py
  • apps/accounts/tests/test_review_fixes.py
  • apps/accounts/tests/test_review_fixes_2.py
  • apps/accounts/tests/test_review_fixes_3.py
  • apps/accounts/tests/test_review_fixes_4.py
  • config/tests/test_cache.py
  • config/tests/test_celery_review_fixes.py
  • config/tests/test_database_url.py
  • config/tests/test_email_backend.py
  • config/tests/test_parallel_spawn.py
  • config/tests/test_settings.py
  • config/tests/test_settings_env_file.py
  • config/tests/test_settings_review_fixes.py

config/tests/test_celery.py also subclasses TestCase but has no PT hits, so it is not exempt. Convert it in the same pass.

Work

  • Rewrite each file with plain functions, assert, pytest.raises, and fixtures (db, settings, monkeypatch, factories) in place of TestCase methods.
  • Remove the file's entry from per-file-ignores in the same change. Files can go in separate pull requests.
  • Keep every test's intent. Coverage must not drop.

Check first

  • config/tests/test_parallel_spawn.py runs a probe suite through manage.py test --parallel 2. The probe is a string of SimpleTestCase code that must stay unittest-style, because manage.py test only discovers those. Convert only the outer test.

Done when

  • per-file-ignores in pyproject.toml has no PT entries.
  • uv run ruff check . and uv run pytest pass.
Dominant language
Python
Stars
0
Forks
1
Avg merge
1h 7m
Merged PRs (30d)
206

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from openpickleball/backend

All issues in openpickleball/backend

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.