Skip to content

test(corekit): test_sentinel_exports_unit passes in the corekit unittest leg - #1386

Merged
JarryShaw merged 1 commit into
mainfrom
fix-1332-sentinel-exports
Oct 8, 2026
Merged

JarryShaw merged 1 commit into
mainfrom
fix-1332-sentinel-exports

Conversation

@JarryShaw

Copy link
Copy Markdown
Owner
  • Searched for similar pull requests
  • Followed the coding style (did not run make pylint/mypy/isort)
  • make test passes — ran only tests/corekit/test_sentinel_exports_unit.py (pytest) and util/run_unittest_leg.py corekit
  • Changelog entry — N/A, added centrally

What is the purpose of your pull request?

  • test — tests only

Closes #1332

test_sentinel_exports_unit.py bound the four sentinels at import, so once an earlier module re-imported pcapkit, assertIs compared a stale object with the canonical one. Fix: classes call reimport_once_per_class in setUp, and the sentinels and BytesField are read inside each test. No assertion is weakened; assertIs stays an identity check.

Before / after (util/run_unittest_leg.py corekit, file-size capped): 593 tests, 5 failures -> 622 tests, 0 failures, 0 errors. Module alone under pytest: 19 passed, 28 subtests passed. The original module fails 5/5 when run after test_fields_collections alone, so the new one is the one that holds.

Polluter. Any earlier module that calls reimport_once_per_class re-imports pcapkit and leaves it in place under plain unittest. The first in leg order is tests/corekit/test_fields_collections.py:25 (setUp), which reaches purge_modules(['pcapkit']) at tests/_support.py:970. Bisected one module at a time: all of test_fields_* (except test_fields_misc_schema_length_1148_unit), test_from_dict_roundtrip_unit, test_infoclass, test_io, test_module, test_multidict trigger it; the test_enum_*, test_protochain* modules do not. This is the helper working as designed (#981), so the stale binding was the sentinel module's fault.

@JarryShaw JarryShaw added test Pull requests that add or correct tests (test: subject prefix) review: running A cross-review is in flight against the current head - no verdict yet labels Oct 7, 2026
@JarryShaw

Copy link
Copy Markdown
Owner Author

Cross-review verdict on d02df663e: NEEDS CHANGES — one line in the same file (Opus reviewed; author Sonnet).

test_star_import_hands_back_the_canonical_object cannot fail. Both sides of its assertIs come from the same shim module: from <shim> import * against <shim>.NULL. A star-import is getattr(shim, name), so the two can never differ. This predates the PR, since main compared against the same shim. The reviewer proved it with a mutation: giving corekit/module.py and corekit/enum.py their own NULL and NO_DEFAULT objects still passes this module 19/19, on both the PR and main. test_sentinels_housing_unit.py does catch it, with 10 failures.

Fix: take expected from importlib.import_module('pcapkit.corekit.sentinels') (the canonical module) rather than from the shim. Against the same mutation that reports module False, enum False, field True, i.e. it catches the broken shims and passes the clean one.

Held up:

  • No weakening: every assertIs, assertIn and assertEqual is unchanged and none was weakened. The NO_VALUE/BytesField identity tests are not vacuous.
  • Results: corekit leg 622 tests, 0 failures (5 on main); the module alone gives 19 passed; tests/project 389 passed.
  • Pollution source confirmed: test_fields_collections followed by main's sentinel module reproduces exactly the 5 failures, and it is the first purger in leg order.

@JarryShaw JarryShaw added review: needs-changes Cross-review at the current head says changes are required; see the verdict comment and removed review: running A cross-review is in flight against the current head - no verdict yet labels Oct 7, 2026
…est leg (#1332)

The module bound the four sentinels at import time, so once an earlier
module in the leg re-imported pcapkit, assertIs compared a stale object
against the canonical one (5 failures).

- Re-import once per class via tests._support.reimport_once_per_class.
- Read the sentinels and BytesField inside each test; no assertion changed.
@JarryShaw
JarryShaw force-pushed the fix-1332-sentinel-exports branch from d02df66 to fc7584e Compare October 7, 2026 22:01
@JarryShaw

Copy link
Copy Markdown
Owner Author

Round-2 verdict on fc7584e1a: GOOD TO GO. I read the delta from d02df663e myself. It is one file, +5/−7. The identity test now runs self.assertIs(namespace[obj], getattr(canonical, obj)) with canonical = importlib.import_module(CANONICAL_MODULE), so the expected object comes from the defining module instead of the shim being star-imported.

The author reran the mutation proof. Giving corekit/module.py and corekit/enum.py their own NULL and NO_DEFAULT now fails exactly those two subtests, and the unchanged field shim still passes. With the mutation reverted, the module alone gives 19 passed and the corekit leg 622 tests, 0 failures.

@JarryShaw JarryShaw added review: good-to-go Cross-review at the current head says ready; CI state is separate and removed review: needs-changes Cross-review at the current head says changes are required; see the verdict comment labels Oct 7, 2026
@JarryShaw JarryShaw moved this to In review in PyPCAPKit Oct 7, 2026
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Coverage: 88.97% (unit tier, Python 3.14, fc7584e1a, Unit Tests run success)

Package Statements Missed Branches Partial Cover
pcapkit (top level) 104 4 20 4 93.55%
pcapkit/const 18777 1032 2348 843 90.27%
pcapkit/corekit 1949 84 606 20 94.91%
pcapkit/dumpkit 189 1 68 1 99.22%
pcapkit/foundation 2443 102 852 39 94.39%
pcapkit/interface 112 7 40 5 92.11%
pcapkit/protocols 16013 206 4178 177 98.06%
pcapkit/toolkit 539 74 168 3 84.58%
pcapkit/utilities 429 4 122 4 98.55%
pcapkit/vendor 4409 2359 1006 158 42.84%

Per-file detail: the coverage-html artifact of this run.

@JarryShaw
JarryShaw merged commit accea09 into main Oct 8, 2026
38 checks passed
@JarryShaw
JarryShaw deleted the fix-1332-sentinel-exports branch October 8, 2026 01:05
@JarryShaw JarryShaw removed the review: good-to-go Cross-review at the current head says ready; CI state is separate label Oct 8, 2026
@JarryShaw JarryShaw added this to the PyPCAPKit v1.5 milestone Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

test(corekit): test_sentinel_exports_unit fails 5 tests in the corekit unittest leg

1 participant