Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions scripts/run_semantic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ def positive_seconds(value):


def read_count(path):
"""The number of tests the child ran, as unittest's own result object reported it."""
"""The number of tests reported by unittest's result object, or None without a valid count."""
try:
with open(path, encoding="utf-8") as handle:
return int(json.load(handle)["testsRun"])
count = json.load(handle)["testsRun"]
except (OSError, ValueError, KeyError, TypeError):
# The child wrote no result: it did not finish, so no test is known to have run.
return 0
return None
return count if type(count) is int and count >= 0 else None


def run_module(directory, module, verbose, timeout=None):
Expand Down Expand Up @@ -183,6 +183,10 @@ def run_module(directory, module, verbose, timeout=None):
_unregister_process(proc)
count = read_count(count_path)
out = stdout + stderr
if count is None:
if proc.returncode == 0:
return 1, 0, out + "\nTest worker exited without reporting a valid unittest result.\n"
return proc.returncode, 0, out
# Discover imports every package initializer, but an empty one has no tests to run. It is included in the
# module list so parallel runs see TestCase classes when there are any; without them, it is not a failure.
if proc.returncode == 5 and count == 0 and module.endswith(".__init__") and "NO TESTS RAN" in stderr:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_run_semantic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,17 @@ def cli(*argv):


class RunnerTest(unittest.TestCase):
def test_parallel_worker_without_a_result_fails_even_if_it_exits_zero(self):
early_exit = ("import os\nimport unittest\nclass T(unittest.TestCase):\n"
" def test_exits_before_reporting(self): os._exit(0)\n")
with tempfile.TemporaryDirectory() as tmp:
suite(tmp, {"helper.py": "X = 1\n", "test_early.py": early_exit, "test_pass.py": PASS})
result = cli(tmp, "-j", "2")
self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
self.assertIn("==== FAILED: test_early", result.stdout)
self.assertIn("Test worker exited without reporting a valid unittest result", result.stdout)
self.assertIn("2 files, 2 tests, 1 files failed", result.stdout)

def test_parallel_timeout_reports_partial_output_and_keeps_healthy_modules(self):
with tempfile.TemporaryDirectory() as tmp:
suite(tmp, {"helper.py": "X = 1\n", "test_hang.py": HANG,
Expand Down
Loading