Skip to content

LCORE-1394: chore: enforce avoiding unittest and fix existing test cases#1251

Merged
tisnik merged 2 commits intolightspeed-core:mainfrom
asamal4:avoid-unittest
Mar 3, 2026
Merged

LCORE-1394: chore: enforce avoiding unittest and fix existing test cases#1251
tisnik merged 2 commits intolightspeed-core:mainfrom
asamal4:avoid-unittest

Conversation

@asamal4
Copy link
Contributor

@asamal4 asamal4 commented Mar 2, 2026

Description

We have agreed to use pytest insted of unittest. This PR is doing below

  • enforcing ruff rule to fail when unittest is used
  • modified existing test cases to use pytest

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: Cursor

Related Tickets & Documents

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

  • Tests

    • Updated many unit tests to use pytest-mock fixtures, adjusted test and helper signatures, and added a small test-only helper to simplify mocking; test behavior unchanged.
  • Chores

    • Extended lint configuration to include rule TID251 for stricter static analysis.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

Warning

Rate limit exceeded

@asamal4 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 13 minutes and 2 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 46ab9e7 and 05ab874.

📒 Files selected for processing (1)
  • pyproject.toml

Walkthrough

Added a Ruff lint block to pyproject.toml and migrated multiple unit tests from unittest.mock to pytest-mock’s mocker fixture (updated imports, signatures, and mock creation). No production/runtime behavior changed.

Changes

Cohort / File(s) Summary
Configuration
pyproject.toml
Inserted [tool.ruff.lint] with extend-select = ["TID251"].
Test - Storage
tests/unit/a2a_storage/test_storage_factory.py
Added module-private _FakeProperty and replaced PropertyMock usages for A2AStateConfiguration.storage_type.
Test - API Endpoints
tests/unit/app/endpoints/test_a2a.py
Replaced unittest.mock usage with mocker.MagicMock/mocker.AsyncMock; tests now accept mocker fixture.
Test - Middleware
tests/unit/app/test_main_middleware.py
Switched to mocker.patch and added mocker: MockerFixture param; added assertion for metrics increment on exception.
Test - Authentication
tests/unit/authentication/test_rh_identity.py
Refactored create_request_with_header to accept mocker: MockerFixture; many tests updated to use mocker.Mock and include mocker param.
Test - Observability (RLSAPI)
tests/unit/observability/formats/test_rlsapi.py
Replaced patch contexts with mocker.patch; test signatures now include mocker: MockerFixture.
Test - Observability (Splunk)
tests/unit/observability/test_splunk.py
Converted fixtures/tests to accept mocker: MockerFixture; replaced direct MagicMock/AsyncMock with mocker.* and generalized helper return types to Any.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

ok-to-test

Suggested reviewers

  • are-ces
  • tisnik
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and specifically describes the main changes: enforcing a ruff rule to prevent unittest usage and fixing existing test cases to use pytest instead, which aligns with the changeset across all modified files.
Docstring Coverage ✅ Passed Docstring coverage is 92.11% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/unit/a2a_storage/test_storage_factory.py (1)

19-27: Silence the new pylint warning on _FakeProperty.

This helper triggers R0903 in CI; add a targeted disable on the class to keep lint output clean.

Proposed minimal lint-only fix
-class _FakeProperty:
+class _FakeProperty:  # pylint: disable=too-few-public-methods
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/a2a_storage/test_storage_factory.py` around lines 19 - 27, Add a
targeted pylint disable for the "too few public methods" warning on the
_FakeProperty test helper by adding a class-level comment like "class
_FakeProperty:  # pylint: disable=R0903" (or a preceding "# pylint:
disable=R0903" immediately above the class) so the R0903 warning is silenced
without changing behavior.
tests/unit/authentication/test_rh_identity.py (1)

436-443: Optional: suppress pylint “too many arguments” for this parametrized test.

This is test-only scaffolding; a local disable keeps CI output clean without changing behavior.

Proposed lint-only adjustment
-    async def test_entitlement_validation(
+    async def test_entitlement_validation(  # pylint: disable=too-many-arguments,too-many-positional-arguments
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/authentication/test_rh_identity.py` around lines 436 - 443, For
the parametrized test function test_entitlement_validation, suppress the pylint
warning by adding a lint-only disable for too-many-arguments (e.g., add "#
pylint: disable=too-many-arguments" on the def line or immediately above it) and
include a short comment stating this is test-only scaffolding so CI output
remains clean; do not change the function signature or behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@tests/unit/authentication/test_rh_identity.py`:
- Line 328: Calls to create_request_with_header are missing a space after the
comma (e.g., create_request_with_header(mocker,header_value)), which causes
Black formatting failures; update each call site to add a space after the comma
(create_request_with_header(mocker, header_value)) including the additional
occurrences that use the same helper so all instances (the ones near tests
referencing create_request_with_header) are consistently fixed.

---

Nitpick comments:
In `@tests/unit/a2a_storage/test_storage_factory.py`:
- Around line 19-27: Add a targeted pylint disable for the "too few public
methods" warning on the _FakeProperty test helper by adding a class-level
comment like "class _FakeProperty:  # pylint: disable=R0903" (or a preceding "#
pylint: disable=R0903" immediately above the class) so the R0903 warning is
silenced without changing behavior.

In `@tests/unit/authentication/test_rh_identity.py`:
- Around line 436-443: For the parametrized test function
test_entitlement_validation, suppress the pylint warning by adding a lint-only
disable for too-many-arguments (e.g., add "# pylint: disable=too-many-arguments"
on the def line or immediately above it) and include a short comment stating
this is test-only scaffolding so CI output remains clean; do not change the
function signature or behavior.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6528bc2 and a31c420.

📒 Files selected for processing (7)
  • pyproject.toml
  • tests/unit/a2a_storage/test_storage_factory.py
  • tests/unit/app/endpoints/test_a2a.py
  • tests/unit/app/test_main_middleware.py
  • tests/unit/authentication/test_rh_identity.py
  • tests/unit/observability/formats/test_rlsapi.py
  • tests/unit/observability/test_splunk.py

@asamal4 asamal4 changed the title chore: enforce avoiding unittest and fix existing test cases [LCORE-1394] chore: enforce avoiding unittest and fix existing test cases Mar 2, 2026
Copy link
Contributor

@tisnik tisnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not you update AGENTS.md too?

@asamal4
Copy link
Contributor Author

asamal4 commented Mar 2, 2026

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
tests/unit/authentication/test_rh_identity.py (1)

436-443: ⚠️ Potential issue | 🟡 Minor

Line 436 still triggers pylint argument-count warnings.

Pipeline reports R0913 and R0917 here after adding mocker. Please either reduce parameters or locally disable for this test to keep lint clean.

💡 Minimal fix
-    async def test_entitlement_validation(
+    async def test_entitlement_validation(  # pylint: disable=too-many-arguments,too-many-positional-arguments
         self,
         mocker: MockerFixture,
         user_identity_data: dict,
         required_entitlements: Optional[list[str]],
         should_raise: bool,
         expected_error: Optional[str],
     ) -> None:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/unit/authentication/test_rh_identity.py` around lines 436 - 443, The
test function test_entitlement_validation currently trips pylint R0913/R0917 due
to too many parameters; fix by either reducing parameters (convert some to
fixtures or bundle into a single dict) or add a local pylint disable immediately
above the test definition to silence the warnings (e.g., add a comment like "#
pylint: disable=R0913,R0917" directly above async def
test_entitlement_validation(...)). Reference the test name
test_entitlement_validation when making the change so you modify the correct
function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@tests/unit/authentication/test_rh_identity.py`:
- Around line 436-443: The test function test_entitlement_validation currently
trips pylint R0913/R0917 due to too many parameters; fix by either reducing
parameters (convert some to fixtures or bundle into a single dict) or add a
local pylint disable immediately above the test definition to silence the
warnings (e.g., add a comment like "# pylint: disable=R0913,R0917" directly
above async def test_entitlement_validation(...)). Reference the test name
test_entitlement_validation when making the change so you modify the correct
function.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 43f4336 and 7f0ae49.

📒 Files selected for processing (7)
  • pyproject.toml
  • tests/unit/a2a_storage/test_storage_factory.py
  • tests/unit/app/endpoints/test_a2a.py
  • tests/unit/app/test_main_middleware.py
  • tests/unit/authentication/test_rh_identity.py
  • tests/unit/observability/formats/test_rlsapi.py
  • tests/unit/observability/test_splunk.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/unit/a2a_storage/test_storage_factory.py
  • tests/unit/app/test_main_middleware.py
  • pyproject.toml

Copy link
Contributor

@tisnik tisnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tisnik tisnik merged commit e07897c into lightspeed-core:main Mar 3, 2026
22 checks passed
@tisnik tisnik changed the title [LCORE-1394] chore: enforce avoiding unittest and fix existing test cases LCORE-1394: chore: enforce avoiding unittest and fix existing test cases Mar 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants