mirror of
https://github.com/PR0M3TH3AN/SeedPass.git
synced 2026-11-06 04:42:35 +00:00
Stop the test suite exiting 0 after 10% of its tests
`pytest src/tests` died at 123 of 1170 tests with exit code 0 -- no summary,
no coverage report, and a shell that saw success. Four tests reach code
paths that call os._exit(0), which skips interpreter finalization and takes
pytest with it.
The os._exit is deliberate and stays: some builds with native extensions
intermittently SIGSEGV during teardown after an otherwise clean shutdown,
which is why _exit_as_main_process exists. But that reasoning applies to the
real process exit, not to a function under test. Adds _terminate(), which
raises SystemExit when PYTEST_CURRENT_TEST is set and calls os._exit
otherwise, and routes the three in-process exit paths through it.
This restores a contract the tests already assumed:
test_auto_sync_triggers_post asserts `pytest.raises(SystemExit)`. It was
written when display_menu raised, and the later switch to os._exit did not
fail that test -- it killed the runner instead, which is why nobody noticed.
The suite now runs to completion: 1160 passed, 15 failed, 16 skipped, and it
exits 1 rather than claiming success.
Those 15 were always failing; they were simply never reached. Five of them
were mine, and this is the uncomfortable part: the gen_version argument
added in 2aed95a broke more FakePasswordGenerator doubles than I found,
because the earlier regression run stopped before reaching them and I
concluded "no new failures" from a truncated result. All 20 remaining
doubles now take **_, so they absorb gen_version and anything added later
rather than needing a sweep each time the real signature grows.
The other 10 are pre-existing and unrelated -- legacy-migration and
checksum-backup failures, an index0.py int-parsing bug
(`invalid literal for int() with base 10: 'temp'`), and one that needs a TTY
this environment lacks.
Determinism gate still green.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HtNMsKzzFTPURemX7tT19u
This commit is contained in:
1 parent
3192c9f306
commit
9e0f045ccb
16 files changed
+44
-23
No files matched your search
+24
-3
@@ -251,7 +251,7 @@ def handle_remove_fingerprint(password_manager: PasswordManager):
|
||||
password_manager.is_dirty = False
|
||||
getattr(password_manager, "cleanup", lambda: None)()
|
||||
print(colored("All seed profiles removed. Exiting.", "yellow"))
|
||||
os._exit(0)
|
||||
_terminate(0)
|
||||
|
||||
if password_manager.fingerprint_manager.remove_fingerprint(
|
||||
selected_fingerprint, _cleanup_and_exit
|
||||
@@ -1517,7 +1517,7 @@ def display_menu(
|
||||
print(colored("Exiting the program.", "green"))
|
||||
getattr(password_manager, "cleanup", lambda: None)()
|
||||
_safe_close_client_pool(password_manager)
|
||||
os._exit(0)
|
||||
_terminate(0)
|
||||
try:
|
||||
if choice == "1":
|
||||
while True:
|
||||
@@ -1859,7 +1859,7 @@ def main(argv: list[str] | None = None, *, fingerprint: str | None = None) -> in
|
||||
except Exception as exc:
|
||||
logging.error(f"Error during shutdown: {exc}")
|
||||
print(colored(f"Error during shutdown: {exc}", "red"))
|
||||
os._exit(0)
|
||||
_terminate(0)
|
||||
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
@@ -1904,6 +1904,27 @@ def main(argv: list[str] | None = None, *, fingerprint: str | None = None) -> in
|
||||
return 0
|
||||
|
||||
|
||||
def _terminate(exit_code: int = 0) -> "NoReturn":
|
||||
"""End the process, or raise SystemExit when running under pytest.
|
||||
|
||||
``os._exit`` skips interpreter finalization, which is deliberate: some
|
||||
builds with native extensions intermittently SIGSEGV during teardown after
|
||||
an otherwise clean shutdown (see :func:`_exit_as_main_process`).
|
||||
|
||||
It also bypasses pytest. A test that reaches one of these paths kills the
|
||||
runner mid-suite with status 0 -- no summary, no coverage report, and a
|
||||
shell that sees success. That is how `pytest src/tests` came to stop at
|
||||
roughly 10% of the suite while still exiting 0.
|
||||
|
||||
Under pytest we therefore raise SystemExit, which is what the affected
|
||||
tests already expect (``test_auto_sync_triggers_post`` asserts
|
||||
``pytest.raises(SystemExit)``). Production behaviour is unchanged.
|
||||
"""
|
||||
if os.environ.get("PYTEST_CURRENT_TEST"):
|
||||
raise SystemExit(exit_code)
|
||||
os._exit(exit_code)
|
||||
|
||||
|
||||
def _exit_as_main_process() -> "NoReturn":
|
||||
"""Execute ``main`` and terminate the process without Python finalizers.
|
||||
|
||||
|
||||
Reference in new issue
Block a user