Skip to content

Commit

Permalink
- switched to asyncio-friendly test running and coverage gathering
Browse files Browse the repository at this point in the history
  while prompting for tests, so that they don't block the event loop.
  This should avoid the OpenAI API timeouts we occasionally saw;
  • Loading branch information
jaltmayerpizzorno committed Feb 6, 2024
1 parent 6314a9e commit fdbd97b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/coverup/coverup.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,12 +498,14 @@ def pl(item, singular, plural = None):
return False # not finished: needs a missing module

try:
result = measure_coverage(test=last_test, tests_dir=args.tests_dir, pytest_args=args.pytest_args,
log_write=lambda msg: log_write(seg, msg))
result = await measure_test_coverage(test=last_test, tests_dir=args.tests_dir, pytest_args=args.pytest_args,
log_write=lambda msg: log_write(seg, msg))

except subprocess.TimeoutExpired:
log_write(seg, "measure_coverage timed out")
return False # try again next time
# FIXME is the built-in timeout reasonable? Do we prompt for a faster test?
# We don't want slow tests, but there may not be any way around it.
return True

except subprocess.CalledProcessError as e:
state.inc_counter('F')
Expand Down
9 changes: 5 additions & 4 deletions src/coverup/testrunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
import json
import re
from .delta import DeltaDebugger, _compact
from .utils import subprocess_run


def measure_coverage(*, test: str, tests_dir: Path, pytest_args='', log_write=None):
async def measure_test_coverage(*, test: str, tests_dir: Path, pytest_args='', log_write=None):
"""Runs a given test and returns the coverage obtained."""
with tempfile.NamedTemporaryFile(prefix="tmp_test_", suffix='.py',
dir=str(tests_dir), mode="w") as t:
Expand All @@ -18,9 +19,9 @@ def measure_coverage(*, test: str, tests_dir: Path, pytest_args='', log_write=No

with tempfile.NamedTemporaryFile() as j:
# -qq to cut down on tokens
p = subprocess.run((f"{sys.executable} -m slipcover --branch --json --out {j.name} " +
f"-m pytest {pytest_args} -qq --disable-warnings {t.name}").split(),
check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, timeout=60)
p = await subprocess_run((f"{sys.executable} -m slipcover --branch --json --out {j.name} " +
f"-m pytest {pytest_args} -qq --disable-warnings {t.name}").split(),
check=True, timeout=60)
if log_write:
log_write(str(p.stdout, 'UTF-8'))

Expand Down

0 comments on commit fdbd97b

Please sign in to comment.