Skip to content

tests: stop re-importing pcapkit before every test (purge_modules dominates suite time) #1065

Closed

Description

@JarryShaw

Is your feature request related to a problem? Please describe.
The #1062 audit found that 1,564 tests across 119 modules (243 call sites) call purge_modules(['pcapkit']) in setUp. That forces a fresh import of pcapkit (329 modules, about 0.67 s) before each of those tests. In the audit, disabling the purge cut pytest time on 192 modules from 1,714 s to 253 s (−85%).

I spot-checked one module on main: tests/protocols/application/test_http_unit.py gave 65 passed / 395 subtests in 77.38 s with the purge, and 0.29 s with it stubbed out.

Describe the solution you'd like
Re-import only where isolation is actually needed. Eight modules fail or hang without the purge: enum_builtin_parity, fields_collections, fields_field, pcapng_unit, dispatch_reachability, tcp_http_dispatch, test_support_helpers, and foundation/test_extraction (hangs). Candidate approaches:

  • purge once per class in setUpClass;
  • purge only in the modules that need it;
  • find and fix the state those eight depend on.

The plain-unittest leg's cross-generation check (#981) must keep catching what it catches today.

Describe alternatives you've considered
Deleting tests: #1062 found that the genuinely redundant ones would save about 2 s.

Additional context
Raw data is in the #1062 audit (/tmp/audit1062/ on the audit host). Related: #1052.

Activity

  1. added this to the 1.5 milestone on Oct 6, 2026
  2. added
    testPull requests that add or correct tests (test: subject prefix)
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Oct 6, 2026
  3. JarryShaw commented on Oct 6, 2026

    @JarryShaw
    OwnerAuthor

    Proceeding: the #1062 ruling bundles the five audit trims into this work. On approach, the default taken is to purge only where isolation is actually needed: once per class, or only in the modules measured to depend on it. The #981 cross-generation check in the plain-unittest leg must still catch what it catches today. A worker is on it; say if you'd rather a different approach.

  4. added
    wipWork in flight - a covering PR is open or an agent is actively on it
    and removed
    needs: decisionWaiting on the maintainer to decide — not blocked by other work
    on Oct 6, 2026
  5. JarryShaw commented on Oct 6, 2026

    @JarryShaw
    OwnerAuthor

    And the re-import fix is accepted. Taking your recommendations.

  6. removed
    wipWork in flight - a covering PR is open or an agent is actively on it
    on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testPull requests that add or correct tests (test: subject prefix)

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions