Skip to content

Commit 5f38c12

Browse files
author
buildbot
committed
Added a custom UnitTest Step class, for the django test steps.
- Legacy-Id: 9254
1 parent 9217759 commit 5f38c12

1 file changed

Lines changed: 66 additions & 3 deletions

File tree

buildbot/masters/datatracker/master.cfg

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ c['change_source'] = [
5050
# case, just kick off a 'runtests' build
5151

5252
from buildbot.schedulers.basic import SingleBranchScheduler, AnyBranchScheduler
53-
from buildbot.schedulers.forcesched import ForceScheduler
5453
from buildbot.changes import filter
5554
c['schedulers'] = [
5655
AnyBranchScheduler(name="pyflakes", treeStableTimer=10, builderNames=["Check PyFlakes"]),
@@ -85,6 +84,70 @@ class TestCrawlerShellCommand(WarningCountingShellCommand):
8584
command=["bin/test-crawl"]
8685
warningPattern = '.* FAIL'
8786

87+
class UnitTest(WarningCountingShellCommand):
88+
89+
name = "test"
90+
warnOnFailure = 1
91+
description = ["testing"]
92+
descriptionDone = ["test"]
93+
command = ["python", "-m", "unittest", "discover"]
94+
95+
regexPatterns = {
96+
"total": "Ran (\d+) tests in [0-9.]+s",
97+
"time": "Ran \d+ tests in ([0-9.]+)s",
98+
"skipped": "(?:OK|FAILED).*\skipped=(\d+)",
99+
"failed": "FAILED.*failures\=(\d+)",
100+
"errors": "FAILED.*errors\=(\d+)",
101+
"template_coverage":" *Template coverage: +([0-9.]+%)",
102+
"url_coverage": " *Url coverage: +([0-9.]+%)",
103+
"code_coverage": " *Code coverage: +([0-9.]+%)",
104+
}
105+
106+
def setTestResults(self, **kwargs):
107+
"""
108+
Called by subclasses to set the relevant statistics; this actually
109+
adds to any statistics already present
110+
"""
111+
for kw in kwargs:
112+
value = kwargs[kw]
113+
if value.isdigit():
114+
# Counter
115+
value = int(value)
116+
value += self.step_status.getStatistic(kw, 0)
117+
elif re.match("[0-9]+\.[0-9]+$"):
118+
# Runtime
119+
value = float(value)
120+
value += self.step_status.getStatistic(kw, 0)
121+
else:
122+
# This is a percentage, and we can't add them
123+
pass
124+
self.step_status.setStatistic(kw, value)
125+
126+
def createSummary(self, log):
127+
info = {}
128+
for line in log.getText().split("\n"):
129+
for key in regexPatterns:
130+
regex = regexPatterns[key]
131+
match = re.match(regex, line)
132+
if match:
133+
info[key] = match.group(1)
134+
self.setTestResults(**info)
135+
136+
def describe(self, done=False):
137+
description = WarningCountingShellCommand.describe(self, done)
138+
if done:
139+
description = description[:] # make a private copy
140+
for name in self.step_status.statistics:
141+
value = self.step_status.getStatistic(name)
142+
if type(value) is float: # this is run-time
143+
description.append('%.2fs %s' % (value, name))
144+
elif type(value) is int:
145+
description.append('%d %s' % (value, name))
146+
else:
147+
description.append('%s %s' % (value, name))
148+
return description
149+
150+
88151
## Set up builders
89152

90153
c['builders'] = []
@@ -139,7 +202,7 @@ factory.addStep(ShellCommand(
139202
haltOnFailure=True,
140203
command=["pip", "install", "-r", "requirements.txt"],
141204
))
142-
factory.addStep(Test(
205+
factory.addStep(UnitTest(
143206
workdir=Interpolate('build/%(src::branch)s'),
144207
haltOnFailure=True,
145208
command=["ietf/manage.py", "test", "--settings=settings_sqlitetest"],
@@ -173,7 +236,7 @@ factory.addStep(ShellCommand(
173236
haltOnFailure=True,
174237
command=["pip", "install", "-r", "requirements.txt"],
175238
))
176-
factory.addStep(Test(
239+
factory.addStep(UnitTest(
177240
workdir=Interpolate('build/%(src::branch)s'),
178241
haltOnFailure=True,
179242
command=["ietf/manage.py", "test", "--settings=settings_sqlitetest"],

0 commit comments

Comments
 (0)