Skip to content

Scope Warning handling in tests to DeprecationWarning#3541

Merged
arkid15r merged 5 commits into
vacanza:devfrom
PPsyrius:test_warning_tightening
Apr 22, 2026
Merged

Scope Warning handling in tests to DeprecationWarning#3541
arkid15r merged 5 commits into
vacanza:devfrom
PPsyrius:test_warning_tightening

Conversation

@PPsyrius

@PPsyrius PPsyrius commented Apr 16, 2026

Copy link
Copy Markdown
Collaborator

Proposed change

  • Since deprecated Korea and Swaziland only emit DeprecationWarning, we can narrow our test assertions from Warning to DeprecationWarning. I spotted this earlier while working on Refactor India holidays testcases #3524.
  • Switch to # mypy: disable-error-code=attr-defined for test_solomon_islands.py
  • Adjusts stacklevel for warnings so that they actually warn where it matters:
Warning (from warnings module):
  File "D:\python-holidays\New Python Script.py", line 4
    xx_public = holidays.CountryHoliday("FR", years=2000)
DeprecationWarning: CountryHoliday is deprecated, use country_holidays instead.
Warning (from warnings module):
  File "D:\python-holidays\New Python Script.py", line 4
    xx_public = holidays.Korea(years=2000)
DeprecationWarning: Korea is deprecated, use SouthKorea instead.
Warning (from warnings module):
  File "D:\python-holidays\New Python Script.py", line 4
    xx_public = holidays.Swaziland(years=2000)
DeprecationWarning: Swaziland is deprecated, use Eswatini instead.

Note

The other 2 warnings.warn in HolidayBase are not getting the stacklevel treatment because the inheritance chain (ObservedHolidayBase \ NoHolidayBase) alters the call stack depth, which would cause warnings to still point to incorrect call sites.

Type of change

  • New country/market holidays support (thank you!)
  • Supported country/market holidays update (calendar discrepancy fix, localization)
  • Existing code/documentation/test/process quality improvement (best practice, cleanup, refactoring, optimization)
  • Dependency update (version deprecation/pin/upgrade)
  • Bugfix (non-breaking change which fixes an issue)
  • Breaking change (a code change causing existing functionality to break)
  • New feature (new holidays functionality in general)

Checklist

@coderabbitai

coderabbitai Bot commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 82c606ad-5273-4f6a-b127-beb3c54caf16

📥 Commits

Reviewing files that changed from the base of the PR and between c0e51f3 and 54398f6.

📒 Files selected for processing (1)
  • tests/countries/test_solomon_islands.py

Summary by CodeRabbit

  • Bug Fixes

    • Improved deprecation warnings to correctly point to the line in your code when using deprecated country classes.
  • Tests

    • Updated test assertions to verify correct deprecation warning types and improved type checking configuration.

Walkthrough

Updated deprecation warnings and tests: tests now assert DeprecationWarning specifically; deprecation warnings.warn(...) calls in country classes and utils now include explicit stacklevel values; a mypy directive replaced per-line ignores in one test module.

Changes

Cohort / File(s) Summary
Test warning assertions
tests/countries/test_eswatini.py, tests/countries/test_south_korea.py
Tightened tests to assert DeprecationWarning instead of a generic Warning.
Country deprecation warnings
holidays/countries/eswatini.py, holidays/countries/south_korea.py
warnings.warn(...) updated to pass stacklevel=3 for the deprecated Swaziland/Korea constructors.
Core utils deprecation
holidays/utils.py
CountryHoliday deprecation warning updated to include stacklevel=2.
Mypy / test cleanup
tests/countries/test_solomon_islands.py
Added module-level # mypy: disable-error-code=attr-defined and removed several per-line # type: ignore[attr-defined] annotations; runtime behavior unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • arkid15r
  • KJhellico
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main objective: narrowing test assertions from generic Warning to DeprecationWarning for deprecated classes.
Description check ✅ Passed The description clearly explains the changes: tightening warning assertions, updating mypy directives, and adjusting stacklevel for better warning visibility.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented Apr 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (36b1e39) to head (afd4962).
⚠️ Report is 2 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##               dev     #3541   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          313       313           
  Lines        18693     18693           
  Branches      2389      2389           
=========================================
  Hits         18693     18693           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@holidays/countries/eswatini.py`:
- Around line 75-77: The DeprecationWarning in Swaziland.__init__ uses
stacklevel=3 which points one frame too high; update the warnings.warn call in
the Swaziland constructor to use stacklevel=2 so the warning references the
caller that invoked Swaziland(), keeping the same message and warning class
(DeprecationWarning).

In `@holidays/countries/south_korea.py`:
- Around line 290-292: The deprecation warning in Korea.__init__ uses
stacklevel=3 which points one frame too far; update the warnings.warn call
inside the Korea class (the "Korea is deprecated, use SouthKorea instead."
warning) to use stacklevel=2 so the reported location points to the direct
caller (test code) instantiating Korea().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: de07812c-d386-4c26-abe1-42964529edef

📥 Commits

Reviewing files that changed from the base of the PR and between 2340315 and c0e51f3.

📒 Files selected for processing (3)
  • holidays/countries/eswatini.py
  • holidays/countries/south_korea.py
  • holidays/utils.py

Comment thread holidays/countries/eswatini.py
Comment thread holidays/countries/south_korea.py

@KJhellico KJhellico left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM.

@sonarqubecloud

Copy link
Copy Markdown

@arkid15r arkid15r left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I needed a deeper look into this which I couldn't afford before the recent release.

So it seems it has a nearly 0 risk to break something for end-users.
Thanks for narrowing the scope down @PPsyrius 👍

@arkid15r arkid15r added this pull request to the merge queue Apr 22, 2026
Merged via the queue into vacanza:dev with commit db21b25 Apr 22, 2026
32 checks passed
@PPsyrius PPsyrius deleted the test_warning_tightening branch April 23, 2026 02:40
@arkid15r arkid15r mentioned this pull request May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants