Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add comprehensive tests for MemoryUsage extension#7009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
AlsaeedHasan wants to merge1 commit intoscrapy:master
base:master
Choose a base branch
Loading
fromAlsaeedHasan:add-memusage-tests

Conversation

@AlsaeedHasan
Copy link

@AlsaeedHasanAlsaeedHasan commentedAug 16, 2025
edited
Loading

Summary

This PR introduces a new comprehensive test suite for theMemoryUsage extension intests/test_memusage.py,Fixes#7002.

Coverage

  • Extension Initialization

    • Enabled only whenMEMUSAGE_ENABLED = True
    • Default/custom settings initialization
    • RaisesNotConfigured whenresource module is unavailable
  • Memory Size Calculation

    • get_virtual_size() behavior on macOS (bytes) and Linux (KB)
    • Properly mocksresource.getrusage()
  • Signal Handlers

    • engine_started() with and without memory limits
    • engine_stopped() ensures tasks are properly stopped
    • Correct creation of looping tasks based on settings
  • Memory Monitoring

    • update() correctly updates stats
    • _check_limit() for exceeded/non-exceeded cases
    • Handles scenarios with/without active spiders
    • "Warn once" behavior properly respected
  • Notifications

    • Email notifications for limit and warning thresholds
    • Proper subject formatting and hostname inclusion
    • _send_report() includes engine status and memory info
  • Edge Cases

    • Behavior when no limits are set
    • Warnings only sent once
    • Different memory threshold scenarios tested

Test Quality

  • Proper use ofunittest.mock for external deps (resource, email sending, crawler components)
  • Parametrized tests viapytest.mark.parametrize
  • Consistent with Scrapy’s testing style
  • Platform-specific behavior tested (Linux vs macOS)
  • Covers happy path and edge cases

Results

  • ✅ 22 tests passing locally
  • ⚠️ 2 harmless warnings about un-awaited mocked async coroutines (expected in test context, no functional impact)

Notes

This suite ensures MemoryUsage extension is fully validated, improves confidence in its stability, and aligns with Scrapy’s test patterns.

@codecov
Copy link

codecovbot commentedAug 16, 2025
edited
Loading

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.94%. Comparing base (d3e15a1) to head (24ada03).
⚠️ Report is 44 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@##           master    #7009      +/-   ##==========================================+ Coverage   90.68%   90.94%   +0.26%==========================================  Files         164      164                Lines       12673    12673                Branches     1647     1647              ==========================================+ Hits        11492    11526      +34+ Misses        894      861      -33+ Partials      287      286       -1

see 7 files with indirect coverage changes

@wRAR
Copy link
Member

Please use pre-commit as documented in the contribution docs.

Please don't test internals and private methods, I understand that AI agents generate this when asked for comprehensive tests but we don't need any of this,#7004 (comment) applies here as well.

@wRARwRAR marked this pull request as draftAugust 18, 2025 10:27
@wRAR
Copy link
Member

Hello! Can you please tell us if you are still planning to work on this? Thank you!

@wRARwRAR added the stale labelNov 21, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Coverscrapy.extensions.memusage.MemoryUsage with tests

2 participants

@AlsaeedHasan@wRAR

[8]ページ先頭

©2009-2025 Movatter.jp