mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 09:14:59 +00:00
refactor: Use pytest instead of unittest for running tests
This commit is contained in:
parent
03aa22ba84
commit
aaacd00ecf
1 changed files with 7 additions and 31 deletions
|
@ -747,7 +747,6 @@ def run_test_real(
|
||||||
indentation_errors += sum(1 for line in errors if line.startswith("IndentationError"))
|
indentation_errors += sum(1 for line in errors if line.startswith("IndentationError"))
|
||||||
|
|
||||||
print(errors[-1])
|
print(errors[-1])
|
||||||
errors = errors[:50]
|
|
||||||
errors = "\n".join(errors)
|
errors = "\n".join(errors)
|
||||||
instructions = errors
|
instructions = errors
|
||||||
instructions += prompts.test_failures.format(file_list=file_list)
|
instructions += prompts.test_failures.format(file_list=file_list)
|
||||||
|
@ -788,33 +787,26 @@ def run_test_real(
|
||||||
|
|
||||||
|
|
||||||
def run_unit_tests(testdir, history_fname):
|
def run_unit_tests(testdir, history_fname):
|
||||||
command = [
|
|
||||||
"python",
|
|
||||||
"-m",
|
|
||||||
"unittest",
|
|
||||||
"discover",
|
|
||||||
"-s",
|
|
||||||
str(testdir),
|
|
||||||
"-t",
|
|
||||||
str(testdir),
|
|
||||||
"-p",
|
|
||||||
"*_test.py",
|
|
||||||
]
|
|
||||||
print(" ".join(command))
|
|
||||||
|
|
||||||
timeout = 60
|
timeout = 60
|
||||||
|
|
||||||
|
command = ["pytest"]
|
||||||
|
|
||||||
|
print(" ".join(command))
|
||||||
|
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
command,
|
command,
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
text=True,
|
text=True,
|
||||||
timeout=timeout,
|
timeout=timeout,
|
||||||
|
cwd=testdir,
|
||||||
)
|
)
|
||||||
|
|
||||||
success = result.returncode == 0
|
success = result.returncode == 0
|
||||||
res = result.stdout
|
res = result.stdout
|
||||||
res = cleanup_test_output(res, testdir)
|
res = cleanup_test_output(res, testdir)
|
||||||
|
dump(res)
|
||||||
|
|
||||||
with history_fname.open("a") as fh:
|
with history_fname.open("a") as fh:
|
||||||
fh.write(f"```\n{res}\n```")
|
fh.write(f"```\n{res}\n```")
|
||||||
|
@ -827,23 +819,7 @@ def run_unit_tests(testdir, history_fname):
|
||||||
def cleanup_test_output(output, testdir):
|
def cleanup_test_output(output, testdir):
|
||||||
# remove timing info, to avoid randomizing the response to GPT
|
# remove timing info, to avoid randomizing the response to GPT
|
||||||
res = re.sub(
|
res = re.sub(
|
||||||
r"^Ran \d+ tests in \d+\.\d+s$",
|
r"\bin \d+\.\d+s\b",
|
||||||
"",
|
|
||||||
output,
|
|
||||||
flags=re.MULTILINE,
|
|
||||||
)
|
|
||||||
res = re.sub(
|
|
||||||
r"^====*$",
|
|
||||||
"====",
|
|
||||||
res,
|
|
||||||
flags=re.MULTILINE,
|
|
||||||
)
|
|
||||||
res = re.sub(
|
|
||||||
r"^----*$",
|
|
||||||
"----",
|
|
||||||
res,
|
|
||||||
flags=re.MULTILINE,
|
|
||||||
)
|
|
||||||
|
|
||||||
res = res.replace(str(testdir), str(testdir.name))
|
res = res.replace(str(testdir), str(testdir.name))
|
||||||
return res
|
return res
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue