with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
# Check some numbers in our data assert len(output["suites"]) == 1 assert len(output["suites"][0]["subtests"]) == 10 assertnot any("value"in suite for suite in output["suites"])
# Check if only firstPaint metrics were obtained for subtest in output["suites"][0]["subtests"]: assert"firstPaint"in subtest["name"]
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
# Check some numbers in our data assert len(output["suites"]) == 1 assert len(output["suites"][0]["subtests"]) == 30 assertnot any("value"in suite for suite in output["suites"])
# Check alert threshold settings for suite in output["suites"]: assert suite["alertThreshold"] == 2.0
for subtest in suite["subtests"]: if"firstPaint"in subtest["name"]: assert subtest["alertThreshold"] == 5.0 else: assert subtest["alertThreshold"] == 2.0
metadata.clear_results() with MOCHITEST_DATA.open() as f:
metadata.add_result(json.loads(f.read()))
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
# Check some numbers in our data assert len(output["suites"]) == 1 assert len(output["suites"][0]["subtests"]) == 5 assertnot any("value"in suite for suite in output["suites"])
# Check if only mochitest metrics were obtained
checked = 0 for subtest in output["suites"][0]["subtests"]: assert"mochitest-metric"in subtest["name"]
if subtest["name"] == "mochitest-metric1": assert subtest.get("value") == 227.67 assert subtest.get("unit") == "cli-unit" assert subtest.get("shouldAlert") assertnot subtest.get("lowerIsBetter")
checked += 1 elif subtest["name"] == "mochitest-metric2": # Default with no CLI arg is False assert subtest.get("value") == 1662.995 assert subtest.get("unit") == "metric-unit"
checked += 1 elif subtest["name"] == "mochitest-metric3": # CLI args should be overriden assertnot subtest.get("shouldAlert") assertnot subtest.get("lowerIsBetter")
checked += 1 elif subtest["name"] == "mochitest-metric4": # Setting from test should be False assertnot subtest.get("shouldAlert") assert subtest.get("lowerIsBetter")
checked += 1 elif subtest["name"] == "mochitest-metric5": # Setting from test should be True assert subtest.get("shouldAlert")
checked += 1
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
# Check some numbers in our data assert len(output["suites"]) == 1 assert"value"notin output["suites"][0] assert any(r > 0for r in output["suites"][0]["subtests"][0]["replicates"])
# Check if only firstPaint/resource metrics were obtained and # that simplifications occurred assert all([ "firstPaint"in subtest["name"] or"duration"in subtest["name"] or"count"in subtest["name"] for subtest in output["suites"][0]["subtests"]
])
found_all = {"firstPaint": False, "count": False, "duration": False} for subtest in output["suites"][0]["subtests"]: if subtest["name"] in found_all:
found_all[subtest["name"]] = True continue assert any([name in subtest["name"] for name in found_all.keys()]) # Statistics are not simplified so any metric that isn't # in the list of known metrics must be a statistic assert"statistics"in subtest["name"]
for entry, value in found_all.items(): assert value, f"Failed finding metric simplification for {entry}"
# Statistics are not simplified by default assert (
len([
subtest for subtest in output["suites"][0]["subtests"] if"statistics"in subtest["name"]
])
== 27
) assert (
len([
subtest for subtest in output["suites"][0]["subtests"] if"statistics"notin subtest["name"]
])
== 3
)
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
# Check some numbers in our data assert len(output["suites"]) == 1 assert"value"notin output["suites"][0] assert any(r > 0for r in output["suites"][0]["subtests"][0]["replicates"])
# In this case, some metrics will be called "median", "mean", etc. # since those are the simplifications of the first statistics entries # that were found. assertnot all([ "firstPaint"in subtest["name"] or"duration"in subtest["name"] or"count"in subtest["name"] for subtest in output["suites"][0]["subtests"]
])
found_all = {"firstPaint": False, "count": False, "duration": False} for subtest in output["suites"][0]["subtests"]: if subtest["name"] in found_all:
found_all[subtest["name"]] = True continue
for entry, value in found_all.items(): assert value, f"Failed finding metric simplification for {entry}"
# Only a portion of the metrics should still have statistics in # their name due to a naming conflict that only emits a warning assert (
len([
subtest for subtest in output["suites"][0]["subtests"] if"statistics"in subtest["name"]
])
== 18
) assert (
len([
subtest for subtest in output["suites"][0]["subtests"] if"statistics"notin subtest["name"]
])
== 12
)
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
assert len(output["suites"]) == 1 assert sorted(output["suites"][0]["extraOptions"]) == sorted(["option"]) assert all([
subtest["shouldAlert"] for subtest in output["suites"][0]["subtests"] if"resource"in subtest["name"]
]) assertnot all([
subtest["shouldAlert"] for subtest in output["suites"][0]["subtests"] if"firstPaint"in subtest["name"]
])
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
assert len(output["suites"]) == 1 assert all([
subtest["unit"] == "a-unit" for subtest in output["suites"][0]["subtests"] if"resource"in subtest["name"]
]) assert all([
subtest["unit"] == "ms" for subtest in output["suites"][0]["subtests"] if"firstPaint"in subtest["name"]
])
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
assert len(output["suites"]) == 1 assert output["suites"][0]["unit"] == "new-unit" assert all([
subtest["unit"] == "a-unit" for subtest in output["suites"][0]["subtests"] if"resource"in subtest["name"]
]) assert all([
subtest["unit"] == "new-unit" for subtest in output["suites"][0]["subtests"] if"firstPaint"in subtest["name"]
])
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
with temp_file() as output:
env.set_arg("output", output) with metrics as m: # , silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
# Check some numbers in our data assert len(output["suites"]) == 1 assert len(output["suites"][0]["subtests"]) == 1 assert"value"notin output["suites"][0] assert any(r > 0for r in output["suites"][0]["subtests"][0]["replicates"])
# Check if only the TimeToDisplayd metric was obtained for subtest in output["suites"][0]["subtests"]: assert"TimeToDisplayed"in subtest["name"]
# Perfherder schema has limits on min/max data values. Having # no metrics in the options will cause a failure because of the # timestamps that are picked up from browsertime. with pytest.raises(jsonschema.ValidationError): with temp_dir() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
# Check some numbers in our data assert len(output["suites"]) == 1 assert len(output["suites"][0]["subtests"]) == 1 assert"value"notin output["suites"][0] assert any(r > 0for r in output["suites"][0]["subtests"][0]["replicates"])
# Check if only firstPaint metric was obtained with 2 replicates assert len(output["suites"][0]["subtests"][0]["replicates"]) == 2 assert ( "browserScripts.timings.firstPaint"
== output["suites"][0]["subtests"][0]["name"]
)
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
# Make sure that application setting is correct assert output["application"]["name"] == "fenix" assert"version"notin output["application"]
with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
output_file = metadata.get_output() with open(output_file) as f:
output = json.loads(f.read())
# Sanity check assert len(output["suites"]) == 1
# We should have 2 subtests (1 per URL) assert len(output["suites"][0]["subtests"]) == 2
# Check to make sure that they were properly split
names = [subtest["name"] for subtest in output["suites"][0]["subtests"]] assert sorted(names) == [ "browserScripts.timings.firstPaint https://www.mozilla.org/en-US/", "browserScripts.timings.firstPaint https://www.sitespeed.io/",
] for i in range(2): assert len(output["suites"][0]["subtests"][i]["replicates"]) == 1
def test_perfherder_bad_app_name():
options = { "app": "this is not an app", "perfherder": True, "perfherder-prefix": "", "perfherder-metrics": [metric_fields("firstPaint")],
}
metrics, metadata, env = setup_env(options)
# This will raise an error because the options method # we use in tests skips the `choices` checks. with pytest.raises(jsonschema.ValidationError): with temp_file() as output:
env.set_arg("output", output) with metrics as m, silence():
m(metadata)
if __name__ == "__main__":
mozunit.main()
Messung V0.5 in Prozent
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.17Bemerkung:
(vorverarbeitet am 2026-08-25)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.