test(vendor): re-resolve VendorRuntimeWarning fresh per generation (#985) - #986
Conversation
) tests/vendor/test_vendor_snapshot_restore_unit.py bound VendorRuntimeWarning at module level, captured at import/collection time. Under plain unittest over tests/vendor (no conftest, no restore_module_table fixture), a sibling module purges pcapkit mid-run and re-imports it, minting a new generation of every pcapkit class -- the same skew #981 pins. The crawler under test then raises a different-generation VendorRuntimeWarning than the one assertWarnsRegex was still holding, so the assertion reports "not triggered" even though the warning is visibly on stderr one line earlier. - Drop the module-level `from pcapkit.utilities.warnings import VendorRuntimeWarning`. - Resolve it fresh in setUp() via importlib.import_module, alongside the vendor_main/Vendor pair that setUp already re-resolves per-test -- the same pattern test_base_class_contract.py's RegistrationGateTests.setUp() uses for #981. - Use self.VendorRuntimeWarning at the one call site. Red: `python -m unittest discover -s tests/vendor` (plain unittest, whole directory) failed with `AssertionError: VendorRuntimeWarning not triggered` on test_a_failure_leaves_the_previous_file_byte_for_byte_intact. Green: same command, Ran 118 tests in ~83s, OK. The module alone still passes: Ran 4 tests in 0.774s, OK.
|
GOOD TO GO at
The fix is complete, and it was the only instance in the directory. Red and green reproduced independently, The order dependence is now measured rather than assumed, and it is tighter than I had framed it:
The binding is captured at import; the assertion fails iff a purging sibling's test runs first. A correction to my own brief: I wrote that On whether this should wait for the broader fix: it should not, and the argument is better than "it is One residual it flagged, non-blocking: UNVERIFIED: pytest on this branch (deliberately — the conftest fixture masks this class, so pytest is not a |
…ing (#985) The setUp docstring added for GitHub issue #985 explained the generation skew by saying assertWarnsRegex "matches by class identity, not by name". unittest's _AssertWarnsContext.__exit__ actually filters with `isinstance(w, self.expected)`, so subclass semantics apply and a genuine subclass of the expected class matches. The docstring's conclusion still holds, for the reason the rewrite now gives: re-importing pcapkit re-mints VendorRuntimeWarning *and* its BaseWarning base, so the two generations are mutually unrelated -- issubclass is false in both directions and their MROs first converge on the builtin UserWarning. isinstance against a stale binding therefore rejects an instance of the fresh generation. Both carry the same __module__ and __name__, which is why the failure message names exactly the class that was raised. Prose only -- no code, assertion or import changed. Measured on CPython 3.14.7: issubclass false both ways, a subclass of the live generation passes assertWarnsRegex, an instance of the other generation fails "VendorRuntimeWarning not triggered". `python -m unittest discover -s tests/vendor`: Ran 118 tests, OK.
|
GOOD TO GO carries to The correction landed, and the worker added a fact better than the one I gave it. I had said So the two generations are not related classes at all; their MROs first converge on the builtin One honest reservation. The No invented correction on the tuple point, which is right: the docstring never claimed a tuple was One environmental note it flagged, worth recording because it will recur: this branch is checked out in UNVERIFIED by it: that under |
tests/vendorfor this exact defect; nothing else fixes this file)make pylint/mypy/isortdon't targettests/, N/A heremake testpasses — not run: pytest'sconftestmasks this defect class, and the full suite OOMs locally. Verified instead with plainunittest discover -s tests/vendor, per test(vendor): a stale warning-class generation makes the snapshot-restore assertion order-dependent #985/test: three modules pass alone but fail together, and pytest reports it green #981What is the purpose of your pull request?
test— tests onlyDescription
Fixes #985.
test_vendor_snapshot_restore_unit.pyboundVendorRuntimeWarningat module level —whatever generation was live at import time. Under plain
unittestovertests/vendor(noconftest), a sibling module purges+reimportspcapkitmid-run, minting a new class generation(same skew as #981).
assertWarnsRegexthen compares against the stale generation while thecrawler raises the current one, so it reports "not triggered" though the warning is on stderr.
Fix: resolve
VendorRuntimeWarninginsetUp()viaimportlib.import_module, alongside thevendor_main/VendorpairsetUpalready re-resolves per test — same pattern asRegistrationGateTests.setUp()intests/test_base_class_contract.py(#984).Red:
unittest discover -s tests/vendor→AssertionError: VendorRuntimeWarning not triggered.Green: same command →
Ran 118 tests in 82.933s / OK. Alone:Ran 4 tests in 0.774s / OK.