Repository navigation
Replace assertion-free mock tests with tests that actually execute (2,513 mock occurrences) #117
Copy link
Copy link
Open
Labels
P1-highRequired for production readinessRequired for production readinesstestingTest suite, CI, coverageTest suite, CI, coverage
Description
Part of #108 · Phase 2 · Depends on the production-mock-removal issue
Problem
60 of 240 test files use mocks; 2,513 total occurrences of unittest.mock|MagicMock|AsyncMock|@patch|patch(|monkeypatch|Mock(. Three of them are inside tests/real_world/, defeating the purpose of that directory entirely.
The project's own rules state: "Do not use mock services for anything ever" and "All tests need to use 'real' function calls."
Representative offenders — tests that mock exactly the thing they claim to test
tests/test_executor_schedulers.py:73-131test_submit_slurm_job_basic— patchestempfile.NamedTemporaryFile,pickle.dump,os.unlink,setup_remote_environment,create_job_script, and stubsconnection_manager.execute_remote_commandto return"Submitted batch job 12345". Then assertsjob_id == "12345". It tests a regex against a string the test itself supplied. No SLURM is involved. Same pattern at:139,:212,:262,:321,:409.tests/test_executor.py:79 test_execute_command—@patch("paramiko.SSHClient"), setsmock_stdout.read.return_value = b"command output", assertsstdout == "command output". Asserts a mock returns what it was told to return.tests/test_ssh_automation.py:123 test_validate_ssh_key_success— mocksparamiko.SSHClient, assertsvalidate_ssh_key(...) is True. No key is ever validated.tests/test_filesystem.py:205 test_remote_ls— mocks SSH, feedsb"file1.txt\nfile2.py\nsubdir/\n", assertsls()returns those three names. Testsstr.splitandrstrip.tests/test_cloud_providers_aws.py:42-44 test_authenticate_success— patchesBOTO3_AVAILABLE = Trueandboto3. Passes on a machine with no boto3 installed at all.tests/test_kubernetes_integration.py:31— fixture patcheskubernetes.clientwholesale;create_namespaced_jobreturns aMockwhose.metadata.nameis"test-job-123". No cluster, no API.tests/test_executor_connections.py:72,103,144,190,215,234,253,279,295— every connection test patchesparamiko.SSHClient. The connection manager is never tested against a socket.
The standard to replace them with
For each subsystem, in preference order:
- Real execution against a real target. SSH/SLURM/PBS/SGE -> a container or the HF Jobs substrate. Filesystem -> a real temp dir and a real SFTP session.
- Real local server. Spin an actual sshd in a container; connect a real socket. This is what
test_executor_connections.pyshould do. - Recorded real interactions (e.g.
vcrpyfor pricing APIs) — recorded once from a genuine call, per the project's "verify with real calls, then record" rule for paid APIs. - Delete. A test that only asserts a mock's configured return value has negative value: it costs maintenance and creates false confidence. Deleting it raises the quality of the suite.
Acceptance criteria
-
grep -rn "unittest.mock" tests/real_world/returns zero — that directory is real-only by definition - Every test named in the list above is either rewritten against a real target or deleted with a stated reason
- Mock occurrences in
tests/reduced by at least an order of magnitude from 2,513 - Each supported backend has at least one test that submits a real job and asserts on a real returned value
- No test asserts equality against a string the same test supplied to a stub
Note
Expect the pass count to drop as this lands, and expect real bugs to surface. That is the point — the cloud-path KeyError in Phase 3 survived precisely because tests mocked past it.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P1-highRequired for production readinessRequired for production readinesstestingTest suite, CI, coverageTest suite, CI, coverage
Activity
jeremymanning commentedon Aug 17, 2026
New evidence from the #109 fix (PR #129): a unit test makes live external API calls.
Instrumenting a full suite run with a socket-blocking
sitecustomizefound 6 connection attempts to Microsoft endpoints (150.171.109.68:443,2603:1061:14:113::1:443) originating from:These reach the live Azure Retail Prices API from tests that run under
-m "not real_world". Not billable (the pricing API is public and free), but they make the "unit" suite network-dependent, flaky offline, and sensitive to a third party's API shape — the same class of problem as thegoogleapiclientbreakage causing 6 of the failures in #114.This is a good candidate for the recorded real interactions tier described in this issue: capture the response once from a genuine call (per the project's "verify with real calls, then record" rule for external APIs), then replay. That keeps the assertion honest about the real API's shape without a network dependency on every run.
Issue #130: pytest.ini was dead config shadowing pyproject.toml (#134)
Fix three fabricated-result bugs, close the RCE, and overhaul the doc…
jeremymanning commentedon Aug 20, 2026
Tracked as a sub-issue of #160 (deferred). Consolidated after a three-agent audit that verified every open issue against the code; see #160 for the plan and the ordering.