2020-12-14 17:05:15 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
from typing import List
|
|
|
|
import sys
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
|
|
|
|
|
2021-03-22 08:16:16 +00:00
|
|
|
def remove_num_threads_option(args: List[str]) -> None:
|
2020-12-14 17:05:15 +00:00
|
|
|
"""Remove -n <n> from argument list"""
|
|
|
|
for i in range(0, len(args)):
|
|
|
|
if args[i] == "-n":
|
|
|
|
del args[i : i + 2]
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
try:
|
|
|
|
subprocess.run(["pytest"] + args, check=True)
|
2021-01-12 22:18:29 +00:00
|
|
|
sys.exit(0)
|
2020-12-14 17:05:15 +00:00
|
|
|
except subprocess.CalledProcessError:
|
2021-01-12 22:18:29 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
# Failed tests. Look up number of failed tests
|
|
|
|
with open(".pytest_cache/v/cache/lastfailed") as f:
|
|
|
|
num_failed = sum(1 for line in f) - 2
|
|
|
|
|
|
|
|
if num_failed > 9:
|
|
|
|
print("More than 9 tests failed. Not rerunning")
|
|
|
|
sys.exit(1)
|
|
|
|
|
2021-11-27 09:57:36 +00:00
|
|
|
print("Rerunning failed tests sequentially")
|
2021-03-22 08:16:16 +00:00
|
|
|
remove_num_threads_option(args)
|
2021-01-12 22:18:29 +00:00
|
|
|
try:
|
|
|
|
subprocess.run(["pytest", "--lf"] + args, check=True)
|
|
|
|
except subprocess.CalledProcessError:
|
|
|
|
sys.exit(1)
|